Skip to content

Commit

Permalink
Deprecate common terms query (#2013)
Browse files Browse the repository at this point in the history
* Deprecate common terms query

* Adapt tests

* Add @deprecated annotations

* Add changelog
  • Loading branch information
deguif authored Nov 16, 2021
1 parent 220c4c2 commit d03212e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Added `bytes` processor [#2008](https://github.com/ruflin/Elastica/pull/2008)
### Changed
### Deprecated
* Deprecated `Elastica\Query\Common` class, use `Elastica\Query\MatchQuery` instead [#2013](https://github.com/ruflin/Elastica/pull/2013)
* Deprecated `Elastica\QueryBuilder\DSL\Query::common_terms()`, use `match()` instead [#2013](https://github.com/ruflin/Elastica/pull/2013)
* Deprecated passing an `int` as 1st argument to `Elastica\Search::setOptionsAndQuery()`, pass an array with the key `size` instead [#2010](https://github.com/ruflin/Elastica/pull/2010)
### Removed
### Fixed
Expand Down
3 changes: 3 additions & 0 deletions src/Query/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

namespace Elastica\Query;

\trigger_deprecation('ruflin/elastica', '7.1.3', 'The "%s" class is deprecated, use "%s" instead. It will be removed in 8.0.', Common::class, MatchQuery::class);

/**
* Class Common.
*
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-common-terms-query.html
* @deprecated since version 7.1.3, use the MatchQuery class instead.
*/
class Common extends AbstractQuery
{
Expand Down
3 changes: 3 additions & 0 deletions src/QueryBuilder/DSL/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,14 @@ public function boosting(): Boosting
* common terms query.
*
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-common-terms-query.html
* @deprecated since version 7.1.3, use the "match()" method instead.
*
* @param float $cutoffFrequency percentage in decimal form (.001 == 0.1%)
*/
public function common_terms(string $field, string $query, float $cutoffFrequency): Common
{
\trigger_deprecation('ruflin/elastica', '7.1.3', 'The "%s()" method is deprecated, use "match()" instead. It will be removed in 8.0.', __METHOD__);

return new Common($field, $query, $cutoffFrequency);
}

Expand Down
10 changes: 10 additions & 0 deletions tests/Query/CommonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@
use Elastica\Document;
use Elastica\Query\Common;
use Elastica\Test\Base as BaseTest;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;

/**
* @internal
*/
class CommonTest extends BaseTest
{
use ExpectDeprecationTrait;

/**
* @group unit
* @group legacy
*/
public function testToArray(): void
{
$this->expectDeprecation('Since ruflin/elastica 7.1.3: The "Elastica\Query\Common" class is deprecated, use "Elastica\Query\MatchQuery" instead. It will be removed in 8.0.');

$query = new Common('body', 'test query', .001);
$query->setLowFrequencyOperator(Common::OPERATOR_AND);

Expand All @@ -34,6 +40,7 @@ public function testToArray(): void

/**
* @group functional
* @group legacy
*/
public function testQuery(): void
{
Expand Down Expand Up @@ -66,6 +73,7 @@ public function testQuery(): void

/**
* @group unit
* @group legacy
*/
public function testSetHighFrequencyOperator(): void
{
Expand All @@ -78,6 +86,7 @@ public function testSetHighFrequencyOperator(): void

/**
* @group unit
* @group legacy
*/
public function testSetBoost(): void
{
Expand All @@ -90,6 +99,7 @@ public function testSetBoost(): void

/**
* @group unit
* @group legacy
*/
public function testSetAnalyzer(): void
{
Expand Down
5 changes: 5 additions & 0 deletions tests/QueryBuilder/DSL/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
use Elastica\Query;
use Elastica\Query\MatchQuery;
use Elastica\QueryBuilder\DSL;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;

/**
* @internal
*/
class QueryTest extends AbstractDSLTest
{
use ExpectDeprecationTrait;

/**
* @group unit
*/
Expand All @@ -36,13 +39,15 @@ public function testMatch(): void

/**
* @group unit
* @group legacy
*/
public function testInterface(): void
{
$queryDSL = new DSL\Query();

$this->_assertImplemented($queryDSL, 'bool', Query\BoolQuery::class, []);
$this->_assertImplemented($queryDSL, 'boosting', Query\Boosting::class, []);
$this->expectDeprecation('Since ruflin/elastica 7.1.3: The "Elastica\QueryBuilder\DSL\Query::common_terms()" method is deprecated, use "match()" instead. It will be removed in 8.0.');
$this->_assertImplemented($queryDSL, 'common_terms', Query\Common::class, ['field', 'query', 0.001]);
$this->_assertImplemented($queryDSL, 'dis_max', Query\DisMax::class, []);
$this->_assertImplemented($queryDSL, 'distance_feature', Query\DistanceFeature::class, ['field', 'now', '7d']);
Expand Down

0 comments on commit d03212e

Please sign in to comment.