Skip to content

Commit

Permalink
update ES6 to RC1 and some minor bc's solved (#1382)
Browse files Browse the repository at this point in the history
  • Loading branch information
p365labs authored and ruflin committed Oct 1, 2017
1 parent 038fc0d commit bf34c22
Show file tree
Hide file tree
Showing 11 changed files with 9 additions and 199 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ All notable changes to this project will be documented in this file based on the
- [Analyze Explain](https://www.elastic.co/guide/en/elasticsearch/reference/6.0/_explain_analyze.html) no more support [request parameters](https://www.elastic.co/guide/en/elasticsearch/reference/5.5/indices-analyze.html), use request body instead. [#1370](https://github.com/ruflin/Elastica/pull/1370)
- [Mapper Attachment plugin has been removed](https://github.com/elastic/elasticsearch/pull/20416) Use Ingest-attachment plugin and attachment processors with pipeline to ingest new documents. [#1375](https://github.com/ruflin/Elastica/pull/1375)
- [Indices](https://github.com/elastic/elasticsearch/pull/21837) Query has been removed in Elasticsearch 6.0 [#1376](https://github.com/ruflin/Elastica/pull/1376)
- Remove deprecated [type and slop](https://github.com/elastic/elasticsearch/pull/26720) field in match query [#1382](https://github.com/ruflin/Elastica/pull/1382)
- Remove [several parse field](https://github.com/elastic/elasticsearch/pull/26711) deprecations in query builders [#1382](https://github.com/ruflin/Elastica/pull/1382)
- Remove [deprecated parameters](https://github.com/elastic/elasticsearch/pull/26508) from ids_query [#1382](https://github.com/ruflin/Elastica/pull/1382)

### Bugfixes
- Enforce [Content-Type requirement on the layer Rest](https://github.com/elastic/elasticsearch/pull/23146), a [PR on Elastica #1301](https://github.com/ruflin/Elastica/issues/1301) solved it (it has been implemented only in the HTTP Transport), but it was not implemented in the Guzzle Transport. [#1349](https://github.com/ruflin/Elastica/pull/1349)
Expand Down
2 changes: 1 addition & 1 deletion env/elasticsearch/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM docker.elastic.co/elasticsearch/elasticsearch:6.0.0-beta2
FROM docker.elastic.co/elasticsearch/elasticsearch:6.0.0-rc1
MAINTAINER Nicolas Ruflin <[email protected]>

RUN /usr/share/elasticsearch/bin/elasticsearch-plugin install ingest-attachment
Expand Down
18 changes: 0 additions & 18 deletions lib/Elastica/Query/ConstantScore.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,6 @@ public function setFilter(AbstractQuery $filter)
return $this->setParam('filter', $filter);
}

/**
* Set query.
*
* @param array|AbstractQuery $query
*
* @throws InvalidException If query is not an array or instance of AbstractQuery
*
* @return $this
*/
public function setQuery($query)
{
if (!is_array($query) && !($query instanceof AbstractQuery)) {
throw new InvalidException('Invalid parameter. Has to be array or instance of Elastica\Query\AbstractQuery');
}

return $this->setParam('query', $query);
}

/**
* Set boost.
*
Expand Down
46 changes: 1 addition & 45 deletions lib/Elastica/Query/Ids.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ class Ids extends AbstractQuery
/**
* Creates filter object.
*
* @param string|\Elastica\Type $type Type to filter on
* @param array $ids List of ids
*/
public function __construct($type = null, array $ids = [])
public function __construct(array $ids = [])
{
$this->setType($type);
$this->setIds($ids);
}

Expand All @@ -40,48 +38,6 @@ public function addId($id)
return $this;
}

/**
* Adds one more type to query.
*
* @param string|\Elastica\Type $type Type name or object
*
* @return $this
*/
public function addType($type)
{
if ($type instanceof ElasticaType) {
$type = $type->getName();
} elseif (empty($type) && !is_numeric($type)) {
// A type can be 0, but cannot be empty
return $this;
}

$this->_params['type'][] = $type;

return $this;
}

/**
* Set type.
*
* @param array|string|\Elastica\Type $type Type name or object
*
* @return $this
*/
public function setType($type)
{
if ($type instanceof ElasticaType) {
$type = $type->getName();
} elseif (empty($type) && !is_numeric($type)) {
// A type can be 0, but cannot be empty
return $this;
}

$this->_params['type'] = (array) $type;

return $this;
}

/**
* Sets the ids to filter.
*
Expand Down
17 changes: 0 additions & 17 deletions lib/Elastica/Query/Match.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,6 @@ public function setFieldQuery($field, $query)
return $this->setFieldParam($field, 'query', $query);
}

/**
* Set field type.
*
* @param string $field
* @param string $type
*
* @return $this
*
* @deprecated Replaced by Elastica\Query\MatchPhrase and Elastica\Query\MatchPhrasePrefix
*/
public function setFieldType($field, $type)
{
trigger_error('Deprecated: Elastica\Query\Match::setFieldType() is deprecated and will be removed in further Elastica releases. Use Elastica\Query\MatchPhrase and Elastica\Query\MatchPhrasePrefix instead.', E_USER_DEPRECATED);

return $this->setFieldParam($field, 'type', $type);
}

/**
* Set field operator.
*
Expand Down
5 changes: 2 additions & 3 deletions lib/Elastica/QueryBuilder/DSL/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,13 @@ public function has_parent($query, $type)
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-ids-query.html
*
* @param array|string|\Elastica\Type $type
* @param array $ids
*
* @return Ids
*/
public function ids($type = null, array $ids = [])
public function ids(array $ids = [])
{
return new Ids($type, $ids);
return new Ids($ids);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Elastica/Suggest/Term.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function setPrefixLength($length)
*/
public function setMinWordLength($length)
{
return $this->setParam('min_word_len', (int) $length);
return $this->setParam('min_word_length', (int) $length);
}

/**
Expand Down
40 changes: 0 additions & 40 deletions test/Elastica/Query/ConstantScoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,46 +52,6 @@ public function testConstruct()
$this->assertEquals($expectedArray, $query->toArray());
}

/**
* @group functional
*/
public function testQuery()
{
$index = $this->_createIndex();

$type = $index->getType('constant_score');
$type->addDocuments([
new Document(1, ['id' => 1, 'email' => '[email protected]', 'username' => 'hans']),
new Document(2, ['id' => 2, 'email' => '[email protected]', 'username' => 'emil']),
new Document(3, ['id' => 3, 'email' => '[email protected]', 'username' => 'ruth']),
]);

// Refresh index
$index->refresh();

$boost = 1.3;
$query_match = new MatchAll();

$query = new ConstantScore();
$query->setQuery($query_match);
$query->setBoost($boost);

$expectedArray = [
'constant_score' => [
'query' => $query_match->toArray(),
'boost' => $boost,
],
];

$this->assertEquals($expectedArray, $query->toArray());
$resultSet = $type->search($query);

$results = $resultSet->getResults();

$this->assertEquals($resultSet->count(), 3);
$this->assertEquals($results[1]->getScore(), 1.3);
}

/**
* @group unit
*/
Expand Down
4 changes: 0 additions & 4 deletions test/Elastica/Query/IdsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ public function testSetTypeSingleSearchSingle()
$query = new Ids();

$query->setIds('1');
$query->setType('helloworld1');

$resultSet = $this->_index->search($query);

Expand All @@ -112,7 +111,6 @@ public function testSetTypeSingleSearchArray()
$query = new Ids();

$query->setIds(['1', '2']);
$query->setType('helloworld1');

$resultSet = $this->_index->search($query);

Expand All @@ -128,7 +126,6 @@ public function testSetTypeSingleSearchSingleDocInOtherType()

// Doc 4 is in the second type...
$query->setIds('4');
$query->setType('helloworld1');

$resultSet = $this->_index->search($query);

Expand All @@ -145,7 +142,6 @@ public function testSetTypeSingleSearchArrayDocInOtherType()

// Doc 4 is in the second type...
$query->setIds(['1', '4']);
$query->setType('helloworld1');

$resultSet = $this->_index->search($query);

Expand Down
69 changes: 0 additions & 69 deletions test/Elastica/Query/MatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public function testToArray()
{
$field = 'test';
$testQuery = 'Nicolas Ruflin';
$type = 'phrase';
$operator = 'and';
$analyzer = 'myanalyzer';
$boost = 2.0;
Expand All @@ -27,7 +26,6 @@ public function testToArray()
$query = new Match();
$query->setFieldQuery($field, $testQuery);
$this->hideDeprecated();
$query->setFieldType($field, $type);
$this->showDeprecated();
$query->setFieldOperator($field, $operator);
$query->setFieldAnalyzer($field, $analyzer);
Expand All @@ -42,7 +40,6 @@ public function testToArray()
'match' => [
$field => [
'query' => $testQuery,
'type' => $type,
'operator' => $operator,
'analyzer' => $analyzer,
'boost' => $boost,
Expand Down Expand Up @@ -179,72 +176,6 @@ public function testMatchZeroTerm()
$this->assertEquals(2, $resultSet->count());
}

/**
* @group functional
*/
public function testMatchPhraseType()
{
$client = $this->_getClient();
$index = $client->getIndex('test');
$index->create([], true);
$type = $index->getType('test');

$type->addDocuments([
new Document(1, ['name' => 'Basel-Stadt']),
new Document(2, ['name' => 'New York']),
new Document(3, ['name' => 'New Hampshire']),
new Document(4, ['name' => 'Basel Land']),
]);

$index->refresh();

$field = 'name';
$type = 'phrase';

$query = new Match();
$query->setFieldQuery($field, 'New York');
$this->hideDeprecated();
$query->setFieldType($field, $type);
$this->showDeprecated();

$resultSet = $index->search($query);

$this->assertEquals(1, $resultSet->count());
}

/**
* @group functional
*/
public function testMatchPhrasePrefixType()
{
$client = $this->_getClient();
$index = $client->getIndex('test');
$index->create([], true);
$type = $index->getType('test');

$type->addDocuments([
new Document(1, ['name' => 'Basel-Stadt']),
new Document(2, ['name' => 'New York']),
new Document(3, ['name' => 'New Hampshire']),
new Document(4, ['name' => 'Basel Land']),
]);

$index->refresh();

$field = 'name';
$type = 'phrase_prefix';

$query = new Match();
$query->setFieldQuery($field, 'New');
$this->hideDeprecated();
$query->setFieldType($field, $type);
$this->showDeprecated();

$resultSet = $index->search($query);

$this->assertEquals(2, $resultSet->count());
}

/**
* @group unit
*/
Expand Down
2 changes: 1 addition & 1 deletion test/Elastica/QueryBuilder/DSL/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testInterface()
$this->_assertImplemented($queryDSL, 'fuzzy', Query\Fuzzy::class, ['field', 'type']);
$this->_assertImplemented($queryDSL, 'has_child', Query\HasChild::class, [new Match()]);
$this->_assertImplemented($queryDSL, 'has_parent', Query\HasParent::class, [new Match(), 'type']);
$this->_assertImplemented($queryDSL, 'ids', Query\Ids::class, ['type', []]);
$this->_assertImplemented($queryDSL, 'ids', Query\Ids::class, [[]]);
$this->_assertImplemented($queryDSL, 'match', Match::class, ['field', 'values']);
$this->_assertImplemented($queryDSL, 'match_all', Query\MatchAll::class, []);
$this->_assertImplemented($queryDSL, 'match_none', Query\MatchNone::class, []);
Expand Down

0 comments on commit bf34c22

Please sign in to comment.