Skip to content
Snippets Groups Projects
Commit 30fb9aef authored by Mantas Varatiejus's avatar Mantas Varatiejus
Browse files

Deprecate filters

parent a644572a
No related branches found
No related tags found
No related merge requests found
Showing
with 619 additions and 177 deletions
......@@ -11,48 +11,22 @@
namespace ONGR\ElasticsearchDSL\Filter;
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
@trigger_error(
'The PrefixFilter class is deprecated and will be removed in 2.0. Use PrefixQuery instead.',
E_USER_DEPRECATED
);
use ONGR\ElasticsearchDSL\Query\PrefixQuery;
/**
* Represents Elasticsearch "prefix" filter.
*
* Filters documents that have fields containing terms with a specified prefix.
*
* @deprecated Will be removed in 2.0. Use the PrefixQuery instead.
*/
class PrefixFilter implements BuilderInterface
class PrefixFilter extends PrefixQuery
{
use ParametersTrait;
/**
* @var string
*/
protected $field;
/**
* @var string
*/
protected $value;
/**
* @param string $field Field name.
* @param string $value Value.
* @param array $parameters Optional parameters.
*/
public function __construct($field, $value, array $parameters = [])
{
$this->field = $field;
$this->value = $value;
$this->setParameters($parameters);
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'prefix';
}
/**
* {@inheritdoc}
*/
......
......@@ -11,11 +11,18 @@
namespace ONGR\ElasticsearchDSL\Filter;
@trigger_error(
'The QueryFilter class is deprecated and will be removed in 2.0.',
E_USER_DEPRECATED
);
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
/**
* Represents Elasticsearch "query" filter.
*
* @deprecated Will be removed in 2.0. The query filter has been removed as queries and filters have been merged.
*/
class QueryFilter implements BuilderInterface
{
......
......@@ -11,28 +11,22 @@
namespace ONGR\ElasticsearchDSL\Filter;
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
@trigger_error(
'The RangeFilter class is deprecated and will be removed in 2.0. Use RangeQuery instead.',
E_USER_DEPRECATED
);
use ONGR\ElasticsearchDSL\Query\RangeQuery;
/**
* Represents Elasticsearch "range" filter.
*
* Filters documents with fields that have terms within a certain range.
*
* @deprecated Will be removed in 2.0. Use the RangeQuery instead.
*/
class RangeFilter implements BuilderInterface
class RangeFilter extends RangeQuery
{
use ParametersTrait;
/**
* @var string
*/
private $field;
/**
* @var array
*/
private $range;
/**
* @param string $field Field name.
* @param array $range Range values.
......@@ -40,28 +34,6 @@ class RangeFilter implements BuilderInterface
*/
public function __construct($field, $range, array $parameters = [])
{
$this->field = $field;
$this->range = $range;
$this->setParameters($parameters);
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'range';
}
/**
* {@inheritdoc}
*/
public function toArray()
{
$query = [$this->field => $this->range];
$output = $this->processArray($query);
return $output;
parent::__construct($field, array_merge($range, $parameters));
}
}
......@@ -11,11 +11,18 @@
namespace ONGR\ElasticsearchDSL\Filter;
@trigger_error(
'The RegexpFilter class is deprecated and will be removed in 2.0. Use RegexpQuery instead.',
E_USER_DEPRECATED
);
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
/**
* Represents Elasticsearch "regexp" filter.
*
* @deprecated Will be removed in 2.0. Use the RegexpQuery instead.
*/
class RegexpFilter implements BuilderInterface
{
......
......@@ -11,6 +11,11 @@
namespace ONGR\ElasticsearchDSL\Filter;
@trigger_error(
'The ScriptFilter class is deprecated and will be removed in 2.0. Use ScriptQuery instead.',
E_USER_DEPRECATED
);
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
......@@ -18,6 +23,8 @@ use ONGR\ElasticsearchDSL\ParametersTrait;
* Represents Elasticsearch "script" filter.
*
* Allows to define scripts as filters.
*
* @deprecated Will be removed in 2.0. Use the ScriptQuery instead.
*/
class ScriptFilter implements BuilderInterface
{
......
......@@ -11,16 +11,20 @@
namespace ONGR\ElasticsearchDSL\Filter;
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
@trigger_error(
'The TermFilter class is deprecated and will be removed in 2.0. Use TermQuery instead.',
E_USER_DEPRECATED
);
use ONGR\ElasticsearchDSL\Query\TermQuery;
/**
* Represents Elasticsearch "term" filter.
*
* @deprecated Will be removed in 2.0. Use the TermQuery instead.
*/
class TermFilter implements BuilderInterface
class TermFilter extends TermQuery
{
use ParametersTrait;
/**
* @var string
*/
......@@ -29,26 +33,17 @@ class TermFilter implements BuilderInterface
/**
* @var string
*/
private $term;
private $value;
/**
* @param string $field Field name.
* @param string $term Field value.
* @param array $parameters Optional parameters.
* {@inheritdoc}
*/
public function __construct($field, $term, array $parameters = [])
public function __construct($field, $value, array $parameters = [])
{
$this->field = $field;
$this->term = $term;
$this->setParameters($parameters);
}
$this->value = $value;
/**
* {@inheritdoc}
*/
public function getType()
{
return 'term';
parent::__construct($field, $value, $parameters);
}
/**
......@@ -56,7 +51,7 @@ class TermFilter implements BuilderInterface
*/
public function toArray()
{
$query = [$this->field => $this->term];
$query = [$this->field => $this->value];
$output = $this->processArray($query);
......
......@@ -11,55 +11,18 @@
namespace ONGR\ElasticsearchDSL\Filter;
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
@trigger_error(
'The TermsFilter class is deprecated and will be removed in 2.0. Use TermsQuery instead.',
E_USER_DEPRECATED
);
use ONGR\ElasticsearchDSL\Query\TermsQuery;
/**
* Represents Elasticsearch "terms" filter.
*
* @deprecated Will be removed in 2.0. Use the TermsQuery instead.
*/
class TermsFilter implements BuilderInterface
class TermsFilter extends TermsQuery
{
use ParametersTrait;
/**
* @var string
*/
private $field;
/**
* @var array
*/
private $terms;
/**
* @param string $field Field name.
* @param array $terms An array of terms.
* @param array $parameters Optional parameters.
*/
public function __construct($field, $terms, array $parameters = [])
{
$this->field = $field;
$this->terms = $terms;
$this->setParameters($parameters);
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'terms';
}
/**
* {@inheritdoc}
*/
public function toArray()
{
$query = [$this->field => $this->terms];
$output = $this->processArray($query);
return $output;
}
}
......@@ -11,45 +11,20 @@
namespace ONGR\ElasticsearchDSL\Filter;
use ONGR\ElasticsearchDSL\BuilderInterface;
@trigger_error(
'The TypeFilter class is deprecated and will be removed in 2.0. Use TypeQuery instead.',
E_USER_DEPRECATED
);
use ONGR\ElasticsearchDSL\Query\TypeQuery;
/**
* Represents Elasticsearch "type" filter.
*
* Filters documents matching the provided type.
*
* @deprecated Will be removed in 2.0. Use the TypeQuery instead.
*/
class TypeFilter implements BuilderInterface
class TypeFilter extends TypeQuery
{
/**
* @var string
*/
private $type;
/**
* Constructor.
*
* @param string $type Type name.
*/
public function __construct($type)
{
$this->type = $type;
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'type';
}
/**
* {@inheritdoc}
*/
public function toArray()
{
return [
'value' => $this->type,
];
}
}
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchDSL\Query;
use ONGR\ElasticsearchDSL\BuilderInterface;
/**
* Represents Elasticsearch "exists" query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html
*/
class ExistsQuery implements BuilderInterface
{
/**
* @var string
*/
private $field;
/**
* Constructor.
*
* @param string $field Field value
*/
public function __construct($field)
{
$this->field = $field;
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'exists';
}
/**
* {@inheritdoc}
*/
public function toArray()
{
return [
'field' => $this->field,
];
}
}
......@@ -11,6 +11,12 @@
namespace ONGR\ElasticsearchDSL\Query;
@trigger_error(
'The FilteredQuery class is deprecated and will be removed in 2.0. ' .
'Use the "bool" query instead with a "filter" clause.',
E_USER_DEPRECATED
);
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
......@@ -18,6 +24,8 @@ use ONGR\ElasticsearchDSL\ParametersTrait;
* Represents Elasticsearch "bool" filter.
*
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-filtered-query.html
*
* @deprecated Will be removed in 2.0. Use the `bool` query instead with a `filter` clause.
*/
class FilteredQuery implements BuilderInterface
{
......
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchDSL\Query;
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
/**
* Represents Elasticsearch "geo_bounding_box" query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-bounding-box-query.html
*/
class GeoBoundingBoxQuery implements BuilderInterface
{
use ParametersTrait;
/**
* @var array
*/
private $values;
/**
* @var string
*/
private $field;
/**
* @param string $field
* @param array $values
* @param array $parameters
*/
public function __construct($field, $values, array $parameters = [])
{
$this->field = $field;
$this->values = $values;
$this->setParameters($parameters);
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'geo_bounding_box';
}
/**
* {@inheritdoc}
*/
public function toArray()
{
if (count($this->values) === 2) {
$query = [
$this->field => [
'top_left' => $this->values[0],
'bottom_right' => $this->values[1],
],
];
} elseif (count($this->values) === 4) {
$query = [
$this->field => [
'top' => $this->values[0],
'left' => $this->values[1],
'bottom' => $this->values[2],
'right' => $this->values[3],
],
];
} else {
throw new \LogicException('Geo Bounding Box filter must have 2 or 4 geo points set.');
}
$output = $this->processArray($query);
return $output;
}
}
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchDSL\Query;
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
/**
* Represents Elasticsearch "geo_distance" query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html
*/
class GeoDistanceQuery implements BuilderInterface
{
use ParametersTrait;
/**
* @var string
*/
private $field;
/**
* @var string
*/
private $distance;
/**
* @var mixed
*/
private $location;
/**
* @param string $field
* @param string $distance
* @param mixed $location
* @param array $parameters
*/
public function __construct($field, $distance, $location, array $parameters = [])
{
$this->field = $field;
$this->distance = $distance;
$this->location = $location;
$this->setParameters($parameters);
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'geo_distance';
}
/**
* {@inheritdoc}
*/
public function toArray()
{
$query = [
'distance' => $this->distance,
$this->field => $this->location,
];
$output = $this->processArray($query);
return $output;
}
}
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchDSL\Query;
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
/**
* Represents Elasticsearch "geo_distance_range" query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-range-query.html
*/
class GeoDistanceRangeQuery implements BuilderInterface
{
use ParametersTrait;
/**
* @var string
*/
private $field;
/**
* @var array
*/
private $range;
/**
* @var mixed
*/
private $location;
/**
* @param string $field
* @param array $range
* @param mixed $location
* @param array $parameters
*/
public function __construct($field, $range, $location, array $parameters = [])
{
$this->field = $field;
$this->range = $range;
$this->location = $location;
$this->setParameters($parameters);
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'geo_distance_range';
}
/**
* {@inheritdoc}
*/
public function toArray()
{
$query = $this->range + [$this->field => $this->location];
$output = $this->processArray($query);
return $output;
}
}
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchDSL\Query;
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
/**
* Represents Elasticsearch "geo_polygon" query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-polygon-query.html
*/
class GeoPolygonQuery implements BuilderInterface
{
use ParametersTrait;
/**
* @var string
*/
private $field;
/**
* @var array
*/
private $points;
/**
* @param string $field
* @param array $points
* @param array $parameters
*/
public function __construct($field, array $points = [], array $parameters = [])
{
$this->field = $field;
$this->points = $points;
$this->setParameters($parameters);
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'geo_polygon';
}
/**
* {@inheritdoc}
*/
public function toArray()
{
$query = [$this->field => ['points' => $this->points]];
$output = $this->processArray($query);
return $output;
}
}
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchDSL\Query;
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
/**
* Represents Elasticsearch "geo_shape" query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-query.html
*/
class GeoShapeQuery implements BuilderInterface
{
use ParametersTrait;
/**
* @var array
*/
private $fields = [];
/**
* @param array $parameters
*/
public function __construct(array $parameters = [])
{
$this->setParameters($parameters);
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'geo_shape';
}
/**
* Add geo-shape provided filter.
*
* @param string $field Field name.
* @param string $type Shape type.
* @param array $coordinates Shape coordinates.
* @param array $parameters Additional parameters.
*/
public function addShape($field, $type, array $coordinates, array $parameters = [])
{
$filter = array_merge(
$parameters,
[
'type' => $type,
'coordinates' => $coordinates,
]
);
$this->fields[$field]['shape'] = $filter;
}
/**
* Add geo-shape pre-indexed filter.
*
* @param string $field Field name.
* @param string $id The ID of the document that containing the pre-indexed shape.
* @param string $type Name of the index where the pre-indexed shape is.
* @param string $index Index type where the pre-indexed shape is.
* @param string $path The field specified as path containing the pre-indexed shape.
* @param array $parameters Additional parameters.
*/
public function addPreIndexedShape($field, $id, $type, $index, $path, array $parameters = [])
{
$filter = array_merge(
$parameters,
[
'id' => $id,
'type' => $type,
'index' => $index,
'path' => $path,
]
);
$this->fields[$field]['indexed_shape'] = $filter;
}
/**
* {@inheritdoc}
*/
public function toArray()
{
$output = $this->processArray($this->fields);
return $output;
}
}
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchDSL\Query;
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
/**
* Represents Elasticsearch "geohash_cell" query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geohash-cell-query.html
*/
class GeohashCellQuery implements BuilderInterface
{
use ParametersTrait;
/**
* @var string
*/
private $field;
/**
* @var mixed
*/
private $location;
/**
* @param string $field
* @param mixed $location
* @param array $parameters
*/
public function __construct($field, $location, array $parameters = [])
{
$this->field = $field;
$this->location = $location;
$this->setParameters($parameters);
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'geohash_cell';
}
/**
* {@inheritdoc}
*/
public function toArray()
{
$query = [$this->field => $this->location];
$output = $this->processArray($query);
return $output;
}
}
......@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
/**
* Elasticsearch has_child query class.
* Represents Elasticsearch "has_child" query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-child-query.html
*/
class HasChildQuery implements BuilderInterface
{
......
......@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
/**
* Elasticsearch has_parent query class.
* Represents Elasticsearch "has_parent" query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-parent-query.html
*/
class HasParentQuery implements BuilderInterface
{
......
......@@ -15,7 +15,9 @@ use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
/**
* Elasticsearch ids query class.
* Represents Elasticsearch "ids" query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-ids-query.html
*/
class IdsQuery implements BuilderInterface
{
......
......@@ -14,7 +14,9 @@ namespace ONGR\ElasticsearchDSL\Query;
use ONGR\ElasticsearchDSL\BuilderInterface;
/**
* Elasticsearch indices query class.
* Represents Elasticsearch "indices" query.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-indices-query.html
*/
class IndicesQuery implements BuilderInterface
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment