Skip to content

Commit f40b9db

Browse files
committed
Fix SearchTests
1 parent 10461ed commit f40b9db

35 files changed

+123
-398
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file based on the
55

66
### Backward Compatibility Breaks
77
* Deprecated usage of `\Elastica\Type` class, `\Elastica\Index` class must be used instead [#1666](https://github.com/ruflin/Elastica/pull/1666)
8+
* Forced index names to string in `\Elastica\Index::__construct()` [#1666](https://github.com/ruflin/Elastica/pull/1666)
9+
* Removed Type query `\Elastica\Query\Type` [#1666](https://github.com/ruflin/Elastica/pull/1666)
810
* Dropped support for PHP 7.0
911
* \Elastica\AbstractUpdateAction::getOptions( $fields ) no longer supports the $underscore parameter, option names must match what elasticsearch expects.
1012
* Removed no longer supported \Elastica\Query\QueryString::setAutoGeneratePhraseQueries( $bool ) [#1622](https://github.com/ruflin/Elastica/pull/1622)

lib/Elastica/Client.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public function getConfigValue($keys, $default = null)
226226
*
227227
* @return \Elastica\Index Index for the given name
228228
*/
229-
public function getIndex($name)
229+
public function getIndex(string $name)
230230
{
231231
return new Index($this, $name);
232232
}

lib/Elastica/Query/HasParent.php

+1-15
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@ class HasParent extends AbstractQuery
1515
* Construct HasChild Query.
1616
*
1717
* @param string|BaseQuery|AbstractQuery $query
18-
* @param string $type Parent document type
1918
*/
20-
public function __construct($query, string $type)
19+
public function __construct($query)
2120
{
2221
$this->setQuery($query);
23-
$this->setType($type);
2422
}
2523

2624
/**
@@ -35,18 +33,6 @@ public function setQuery($query): self
3533
return $this->setParam('query', BaseQuery::create($query));
3634
}
3735

38-
/**
39-
* Set type of the parent document.
40-
*
41-
* @param string $type Parent document type
42-
*
43-
* @return $this
44-
*/
45-
public function setType(string $type): self
46-
{
47-
return $this->setParam('parent_type', $type);
48-
}
49-
5036
/**
5137
* Sets the scope.
5238
*

lib/Elastica/Query/Type.php

-56
This file was deleted.

lib/Elastica/QueryBuilder/DSL/Query.php

-15
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
use Elastica\Query\SpanWithin;
4242
use Elastica\Query\Term;
4343
use Elastica\Query\Terms;
44-
use Elastica\Query\Type;
4544
use Elastica\Query\Wildcard;
4645
use Elastica\QueryBuilder\DSL;
4746

@@ -565,20 +564,6 @@ public function exists(string $field): Exists
565564
return new Exists($field);
566565
}
567566

568-
/**
569-
* type query.
570-
*
571-
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-type-query.html
572-
*
573-
* @param string $type Type name
574-
*
575-
* @return Type
576-
*/
577-
public function type(string $type = null): Type
578-
{
579-
return new Type($type);
580-
}
581-
582567
/**
583568
* type query.
584569
*

test/Elastica/Aggregation/NestedTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ protected function _getIndexForTest(): Index
1515
{
1616
$index = $this->_createIndex();
1717

18-
$index->setMapping(new Mapping(null, [
18+
$index->setMapping(new Mapping([
1919
'resellers' => [
2020
'type' => 'nested',
2121
'properties' => [

test/Elastica/Aggregation/ParentAggregationTest.php

+12-20
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Elastica\Aggregation\ParentAggregation;
66
use Elastica\Aggregation\Terms;
7-
use Elastica\Document;
87
use Elastica\Mapping;
98
use Elastica\Query;
109

@@ -14,16 +13,9 @@ protected function _getIndexForTest()
1413
{
1514
$client = $this->_getClient();
1615
$index = $client->getIndex('testaggregationparent');
17-
$index->create(['settings' => ['index' => ['number_of_shards' => 2, 'number_of_replicas' => 1]]], true);
16+
$index->create(['settings' => ['index' => ['number_of_shards' => 2, 'number_of_replicas' => 1]]]);
1817

19-
$type = $index->getType(\strtolower(
20-
'typeparent'.\uniqid()
21-
));
22-
23-
$mapping = new Mapping();
24-
$mapping->setType($type);
25-
26-
$mapping = new Mapping($type, [
18+
$mapping = new Mapping([
2719
'text' => ['type' => 'keyword'],
2820
'tags' => ['type' => 'keyword'],
2921
'owner' => ['type' => 'keyword'],
@@ -38,7 +30,7 @@ protected function _getIndexForTest()
3830
$index->setMapping($mapping);
3931
$index->refresh();
4032

41-
$doc1 = new Document(1, [
33+
$doc1 = $index->createDocument(1, [
4234
'text' => 'this is the 1st question',
4335
'tags' => [
4436
'windows-server-2003',
@@ -48,9 +40,9 @@ protected function _getIndexForTest()
4840
'join' => [
4941
'name' => 'question',
5042
],
51-
], $type->getName());
43+
]);
5244

53-
$doc2 = new Document(2, [
45+
$doc2 = $index->createDocument(2, [
5446
'text' => 'this is the 2nd question',
5547
'tags' => [
5648
'windows-server-2008',
@@ -59,36 +51,36 @@ protected function _getIndexForTest()
5951
'join' => [
6052
'name' => 'question',
6153
],
62-
], $type->getName());
54+
]);
6355

6456
$index->addDocuments([$doc1, $doc2]);
6557

66-
$doc3 = new Document(3, [
58+
$doc3 = $index->createDocument(3, [
6759
'text' => 'this is an top answer, the 1st',
6860
'owner' => 'Sam',
6961
'join' => [
7062
'name' => 'answer',
7163
'parent' => 1,
7264
],
73-
], $type->getName(), $index->getName());
65+
]);
7466

75-
$doc4 = new Document(4, [
67+
$doc4 = $index->createDocument(4, [
7668
'text' => 'this is a top answer, the 2nd',
7769
'owner' => 'Sam',
7870
'join' => [
7971
'name' => 'answer',
8072
'parent' => 2,
8173
],
82-
], $type->getName(), $index->getName());
74+
]);
8375

84-
$doc5 = new Document(5, [
76+
$doc5 = $index->createDocument(5, [
8577
'text' => 'this is an answer, the 3rd',
8678
'owner' => 'Troll',
8779
'join' => [
8880
'name' => 'answer',
8981
'parent' => 2,
9082
],
91-
], $type->getName(), $index->getName());
83+
]);
9284

9385
$this->_getClient()->addDocuments([$doc3], ['routing' => 1]);
9486
$this->_getClient()->addDocuments([$doc4, $doc5], ['routing' => 2]);

test/Elastica/Aggregation/ScriptedMetricTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ protected function _getIndexForTest(): Index
1414
{
1515
$index = $this->_createIndex();
1616

17-
$index->setMapping(new Mapping(null, [
17+
$index->setMapping(new Mapping([
1818
'start' => ['type' => 'long'],
1919
'end' => ['type' => 'long'],
2020
]));

test/Elastica/Base.php

+2-9
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,9 @@ protected function _getProxyUrl403()
112112
return 'http://'.$proxyHost.':12346';
113113
}
114114

115-
/**
116-
* @param string $name Index name
117-
* @param bool $delete Delete index if it exists
118-
* @param int $shards Number of shards to create
119-
*
120-
* @return Index
121-
*/
122-
protected function _createIndex($name = null, $delete = true, $shards = 1)
115+
protected function _createIndex(string $name = null, bool $delete = true, int $shards = 1): Index
123116
{
124-
if (\is_null($name)) {
117+
if (null === $name) {
125118
$name = \preg_replace('/[^a-z]/i', '', \strtolower(\get_called_class()).\uniqid());
126119
}
127120

test/Elastica/Collapse/CollapseTest.php

+3-9
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,13 @@ class CollapseTest extends BaseTest
1414
private function _getIndexForCollapseTest()
1515
{
1616
$index = $this->_createIndex();
17-
18-
$mapping = new Mapping();
19-
$mapping->setType($type);
20-
21-
$mapping->setProperties([
17+
$index->setMapping(new Mapping([
2218
'user' => ['type' => 'keyword'],
2319
'message' => ['type' => 'text'],
2420
'date' => ['type' => 'date'],
2521
'likes' => ['type' => 'integer'],
2622
'zip' => ['type' => 'keyword'],
27-
]);
28-
29-
$mapping->send();
23+
]));
3024

3125
$index->addDocuments([
3226
new Document(1, [
@@ -336,6 +330,6 @@ public function testSecondLevelCollapsing()
336330
*/
337331
private function search(Query $query)
338332
{
339-
return $this->_getIndexForCollapseTest()->getType('_doc')->search($query);
333+
return $this->_getIndexForCollapseTest()->search($query);
340334
}
341335
}

test/Elastica/Exception/ResponseExceptionTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Elastica\Document;
66
use Elastica\Exception\ResponseException;
7+
use Elastica\Mapping;
78

89
class ResponseExceptionTest extends AbstractExceptionTest
910
{
@@ -33,11 +34,11 @@ public function testBadType()
3334
{
3435
$index = $this->_createIndex();
3536

36-
$index->setMapping([
37+
$index->setMapping(new Mapping([
3738
'num' => [
3839
'type' => 'long',
3940
],
40-
]);
41+
]));
4142

4243
try {
4344
$index->addDocument(new Document('', [

0 commit comments

Comments
 (0)