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 184 additions and 621 deletions
# Or Filter
__DEPRECATED:__ `OrFilter` is deprecated and will be removed in 2.0. Use `BoolQuery` instead.
> More info about or filter is in the [official elasticsearch docs][1]
A filter that matches documents using the OR boolean operator on other filters.
......
......@@ -11,6 +11,11 @@
namespace ONGR\ElasticsearchDSL\Filter;
@trigger_error(
'The AndFilter class is deprecated and will be removed in 2.0. Use BoolQuery instead.',
E_USER_DEPRECATED
);
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
......@@ -18,6 +23,8 @@ use ONGR\ElasticsearchDSL\ParametersTrait;
* Represents Elasticsearch "and" filter.
*
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-and-filter.html
*
* @deprecated Will be removed in 2.0. Use the BoolQuery instead.
*/
class AndFilter implements BuilderInterface
{
......
......@@ -11,12 +11,19 @@
namespace ONGR\ElasticsearchDSL\Filter;
@trigger_error(
'The BoolFilter class is deprecated and will be removed in 2.0. Use BoolQuery instead.',
E_USER_DEPRECATED
);
use ONGR\ElasticsearchDSL\Query\BoolQuery;
/**
* Represents Elasticsearch "bool" filter.
*
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-filter.html
*
* @deprecated Will be removed in 2.0. Use the BoolQuery instead.
*/
class BoolFilter extends BoolQuery
{
......
......@@ -11,43 +11,20 @@
namespace ONGR\ElasticsearchDSL\Filter;
use ONGR\ElasticsearchDSL\BuilderInterface;
@trigger_error(
'The ExistsFilter class is deprecated and will be removed in 2.0. Use ExistsQuery instead.',
E_USER_DEPRECATED
);
use ONGR\ElasticsearchDSL\Query\ExistsQuery;
/**
* Represents Elasticsearch "exists" filter.
*
* @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-exists-filter.html
*
* @deprecated Will be removed in 2.0. Use the ExistsQuery instead.
*/
class ExistsFilter implements BuilderInterface
class ExistsFilter extends ExistsQuery
{
/**
* @var string
*/
private $field;
/**
* @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,73 +11,18 @@
namespace ONGR\ElasticsearchDSL\Filter;
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
@trigger_error(
'The GeoBoundingBoxFilter class is deprecated and will be removed in 2.0. Use GeoBoundingBoxQuery instead.',
E_USER_DEPRECATED
);
use ONGR\ElasticsearchDSL\Query\GeoBoundingBoxQuery;
/**
* Represents Elasticsearch "Geo Bounding Box" filter.
*
* @deprecated Will be removed in 2.0. Use the GeoBoundingBoxQuery instead.
*/
class GeoBoundingBoxFilter implements BuilderInterface
class GeoBoundingBoxFilter extends GeoBoundingBoxQuery
{
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;
}
}
......@@ -11,65 +11,18 @@
namespace ONGR\ElasticsearchDSL\Filter;
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
@trigger_error(
'The GeoDistanceFilter class is deprecated and will be removed in 2.0. Use GeoDistanceQuery instead.',
E_USER_DEPRECATED
);
use ONGR\ElasticsearchDSL\Query\GeoDistanceQuery;
/**
* Represents Elasticsearch "Geo Distance Filter" filter.
*
* @deprecated Will be removed in 2.0. Use the GeoDistanceQuery instead.
*/
class GeoDistanceFilter implements BuilderInterface
class GeoDistanceFilter extends GeoDistanceQuery
{
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;
}
}
......@@ -11,62 +11,18 @@
namespace ONGR\ElasticsearchDSL\Filter;
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
@trigger_error(
'The GeoDistanceRangeFilter class is deprecated and will be removed in 2.0. Use GeoDistanceRangeQuery instead.',
E_USER_DEPRECATED
);
use ONGR\ElasticsearchDSL\Query\GeoDistanceRangeQuery;
/**
* Represents Elasticsearch "Geo Distance Range Filter" filter.
*
* @deprecated Will be removed in 2.0. Use the GeoDistanceRangeQuery instead.
*/
class GeoDistanceRangeFilter implements BuilderInterface
class GeoDistanceRangeFilter extends GeoDistanceRangeQuery
{
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;
}
}
......@@ -11,55 +11,18 @@
namespace ONGR\ElasticsearchDSL\Filter;
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
@trigger_error(
'The GeoPolygonFilter class is deprecated and will be removed in 2.0. Use GeoPolygonQuery instead.',
E_USER_DEPRECATED
);
use ONGR\ElasticsearchDSL\Query\GeoPolygonQuery;
/**
* Elasticsearch geo polygon filter.
*
* @deprecated Will be removed in 2.0. Use the GeoPolygonQuery instead.
*/
class GeoPolygonFilter implements BuilderInterface
class GeoPolygonFilter extends GeoPolygonQuery
{
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 = [];
$query[$this->field] = ['points' => $this->points];
$output = $this->processArray($query);
return $output;
}
}
......@@ -11,90 +11,18 @@
namespace ONGR\ElasticsearchDSL\Filter;
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
@trigger_error(
'The GeoShapeFilter class is deprecated and will be removed in 2.0. Use GeoShapeQuery instead.',
E_USER_DEPRECATED
);
use ONGR\ElasticsearchDSL\Query\GeoShapeQuery;
/**
* Elasticsearch geo-shape filter.
*
* @deprecated Will be removed in 2.0. Use the GeoShapeQuery instead.
*/
class GeoShapeFilter implements BuilderInterface
class GeoShapeFilter extends GeoShapeQuery
{
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;
}
}
......@@ -11,56 +11,18 @@
namespace ONGR\ElasticsearchDSL\Filter;
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
@trigger_error(
'The GeohashCellFilter class is deprecated and will be removed in 2.0. Use GeohashCellQuery instead.',
E_USER_DEPRECATED
);
use ONGR\ElasticsearchDSL\Query\GeohashCellQuery;
/**
* Represents Elasticsearch "Geohash Cell" filter.
*
* @deprecated Will be removed in 2.0. Use the GeohashCellQuery instead.
*/
class GeohashCellFilter implements BuilderInterface
class GeohashCellFilter extends GeohashCellQuery
{
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 = [];
$query[$this->field] = $this->location;
$output = $this->processArray($query);
return $output;
}
}
......@@ -11,49 +11,32 @@
namespace ONGR\ElasticsearchDSL\Filter;
@trigger_error(
'The HasChildFilter class is deprecated and will be removed in 2.0. Use HasChildQuery instead.',
E_USER_DEPRECATED
);
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\DslTypeAwareTrait;
use ONGR\ElasticsearchDSL\ParametersTrait;
use ONGR\ElasticsearchDSL\Query\HasChildQuery;
/**
* Elasticsearch has_child filter.
*
* @deprecated Will be removed in 2.0. Use the BoolQuery instead.
*/
class HasChildFilter implements BuilderInterface
class HasChildFilter extends HasChildQuery
{
use ParametersTrait;
use DslTypeAwareTrait;
/**
* @var string
*/
private $type;
/**
* @var BuilderInterface
*/
private $query;
/**
* @param string $type
* @param BuilderInterface $query
* @param array $parameters
*
* @throws \InvalidArgumentException
* {@inheritdoc}
*/
public function __construct($type, BuilderInterface $query, array $parameters = [])
{
$this->type = $type;
$this->query = $query;
$this->setParameters($parameters);
$this->setDslType('filter');
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'has_child';
parent::__construct($type, $query, $parameters);
}
/**
......@@ -61,13 +44,13 @@ class HasChildFilter implements BuilderInterface
*/
public function toArray()
{
$query = [
'type' => $this->type,
$this->getDslType() => [$this->query->getType() => $this->query->toArray()],
];
$result = parent::toArray();
$output = $this->processArray($query);
if ($this->getDslType() !== 'query') {
$result[$this->getDslType()] = $result['query'];
unset($result['query']);
}
return $output;
return $result;
}
}
......@@ -11,49 +11,32 @@
namespace ONGR\ElasticsearchDSL\Filter;
@trigger_error(
'The HasParentFilter class is deprecated and will be removed in 2.0. Use HasParentQuery instead.',
E_USER_DEPRECATED
);
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\DslTypeAwareTrait;
use ONGR\ElasticsearchDSL\ParametersTrait;
use ONGR\ElasticsearchDSL\Query\HasParentQuery;
/**
* Elasticsearch has_parent filter.
*
* @deprecated Will be removed in 2.0. Use the HasParentQuery instead.
*/
class HasParentFilter implements BuilderInterface
class HasParentFilter extends HasParentQuery
{
use ParametersTrait;
use DslTypeAwareTrait;
/**
* @var string
*/
private $parentType;
/**
* @var BuilderInterface
*/
private $query;
/**
* @param string $parentType
* @param BuilderInterface $query
* @param array $parameters
*
* @throws \InvalidArgumentException
* {@inheritdoc}
*/
public function __construct($parentType, BuilderInterface $query, array $parameters = [])
public function __construct($type, BuilderInterface $query, array $parameters = [])
{
$this->parentType = $parentType;
$this->query = $query;
$this->setParameters($parameters);
$this->setDslType('filter');
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'has_parent';
parent::__construct($type, $query, $parameters);
}
/**
......@@ -61,13 +44,13 @@ class HasParentFilter implements BuilderInterface
*/
public function toArray()
{
$query = [
'parent_type' => $this->parentType,
$this->getDslType() => [$this->query->getType() => $this->query->toArray()],
];
$result = parent::toArray();
$output = $this->processArray($query);
if ($this->getDslType() !== 'query') {
$result[$this->getDslType()] = $result['query'];
unset($result['query']);
}
return $output;
return $result;
}
}
......@@ -11,49 +11,18 @@
namespace ONGR\ElasticsearchDSL\Filter;
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
@trigger_error(
'The IdsFilter class is deprecated and will be removed in 2.0. Use IdsQuery instead.',
E_USER_DEPRECATED
);
use ONGR\ElasticsearchDSL\Query\IdsQuery;
/**
* Represents Elasticsearch "ids" filter.
*
* @deprecated Will be removed in 2.0. Use the IdsQuery instead.
*/
class IdsFilter implements BuilderInterface
class IdsFilter extends IdsQuery
{
use ParametersTrait;
/**
* @var string[]
*/
private $values;
/**
* @param string[] $values Ids' values.
* @param array $parameters Optional parameters.
*/
public function __construct($values, array $parameters = [])
{
$this->values = $values;
$this->setParameters($parameters);
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'ids';
}
/**
* {@inheritdoc}
*/
public function toArray()
{
$query = [];
$query['values'] = $this->values;
$output = $this->processArray($query);
return $output;
}
}
......@@ -11,10 +11,17 @@
namespace ONGR\ElasticsearchDSL\Filter;
@trigger_error(
'The IndicesFilter class is deprecated and will be removed in 2.0. Use IndicesQuery instead.',
E_USER_DEPRECATED
);
use ONGR\ElasticsearchDSL\BuilderInterface;
/**
* Represents Elasticsearch "indices" filter.
*
* @deprecated Will be removed in 2.0. Use the IndicesQuery instead.
*/
class IndicesFilter implements BuilderInterface
{
......
......@@ -11,43 +11,20 @@
namespace ONGR\ElasticsearchDSL\Filter;
use ONGR\ElasticsearchDSL\BuilderInterface;
@trigger_error(
'The LimitFilter class is deprecated and will be removed in 2.0. Use LimitQuery instead.',
E_USER_DEPRECATED
);
use ONGR\ElasticsearchDSL\Query\LimitQuery;
/**
* Represents Elasticsearch "limit" filter.
*
* A limit filter limits the number of documents (per shard) to execute on.
*
* @deprecated Will be removed in 2.0. Use the LimitQuery instead.
*/
class LimitFilter implements BuilderInterface
class LimitFilter extends LimitQuery
{
/**
* @var int
*/
private $value;
/**
* @param int $value Number of documents (per shard) to execute on.
*/
public function __construct($value)
{
$this->value = $value;
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'limit';
}
/**
* {@inheritdoc}
*/
public function toArray()
{
return [
'value' => $this->value,
];
}
}
......@@ -11,28 +11,20 @@
namespace ONGR\ElasticsearchDSL\Filter;
use ONGR\ElasticsearchDSL\BuilderInterface;
@trigger_error(
'The MatchAllFilter class is deprecated and will be removed in 2.0. Use MatchAllQuery instead.',
E_USER_DEPRECATED
);
use ONGR\ElasticsearchDSL\Query\MatchAllQuery;
/**
* Represents Elasticsearch "match_all" filter.
*
* A filter matches on all documents.
*
* @deprecated Will be removed in 2.0. Use the MatchAllQuery instead.
*/
class MatchAllFilter implements BuilderInterface
class MatchAllFilter extends MatchAllQuery
{
/**
* {@inheritdoc}
*/
public function getType()
{
return 'match_all';
}
/**
* {@inheritdoc}
*/
public function toArray()
{
return [];
}
}
......@@ -11,49 +11,18 @@
namespace ONGR\ElasticsearchDSL\Filter;
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
@trigger_error(
'The MissingFilter class is deprecated and will be removed in 2.0. Use MissingQuery instead.',
E_USER_DEPRECATED
);
use ONGR\ElasticsearchDSL\Query\MissingQuery;
/**
* Represents Elasticsearch "missing" filter.
*
* @deprecated Will be removed in 2.0. Use the MissingQuery instead.
*/
class MissingFilter implements BuilderInterface
class MissingFilter extends MissingQuery
{
use ParametersTrait;
/**
* @var string
*/
private $field;
/**
* @param string $field Field name.
* @param array $parameters Optional parameters.
*/
public function __construct($field, array $parameters = [])
{
$this->field = $field;
$this->setParameters($parameters);
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'missing';
}
/**
* {@inheritdoc}
*/
public function toArray()
{
$query = [];
$query['field'] = $this->field;
$output = $this->processArray($query);
return $output;
}
}
......@@ -11,60 +11,29 @@
namespace ONGR\ElasticsearchDSL\Filter;
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
@trigger_error(
'The NestedFilter class is deprecated and will be removed in 2.0. Use NestedQuery instead.',
E_USER_DEPRECATED
);
use ONGR\ElasticsearchDSL\Query\NestedQuery;
/**
* Nested filter implementation.
*
* @deprecated Will be removed in 2.0. Use the NestedQuery instead.
*/
class NestedFilter implements BuilderInterface
class NestedFilter extends NestedQuery
{
use ParametersTrait;
/**
* @var string
*/
private $path;
/**
* @var BuilderInterface
*/
private $query;
/**
* @param string $path
* @param BuilderInterface $query
* @param array $parameters
*/
public function __construct($path, BuilderInterface $query, array $parameters = [])
{
$this->path = $path;
$this->query = $query;
$this->parameters = $parameters;
}
/**
* {@inheritdoc}
*/
public function getType()
{
return 'nested';
}
/**
* {@inheritdoc}
*/
public function toArray()
{
$query = [
'path' => $this->path,
'filter' => [
$this->query->getType() => $this->query->toArray(),
],
];
$output = $this->processArray($query);
$result = parent::toArray();
$result['filter'] = $result['query'];
unset($result['query']);
return $output;
return $result;
}
}
......@@ -11,6 +11,11 @@
namespace ONGR\ElasticsearchDSL\Filter;
@trigger_error(
'The NotFilter class is deprecated and will be removed in 2.0. Use BoolQuery instead.',
E_USER_DEPRECATED
);
use ONGR\ElasticsearchDSL\BuilderInterface;
use ONGR\ElasticsearchDSL\ParametersTrait;
......@@ -18,6 +23,8 @@ use ONGR\ElasticsearchDSL\ParametersTrait;
* Represents Elasticsearch "not" filter.
*
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-not-filter.html
*
* @deprecated Will be removed in 2.0. Use the BoolQuery instead.
*/
class NotFilter implements BuilderInterface
{
......
......@@ -11,10 +11,17 @@
namespace ONGR\ElasticsearchDSL\Filter;
@trigger_error(
'The OrFilter class is deprecated and will be removed in 2.0. Use BoolQuery instead.',
E_USER_DEPRECATED
);
/**
* Represents Elasticsearch "or" filter.
*
* @link http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-or-filter.html
*
* @deprecated Will be removed in 2.0. Use the BoolQuery instead.
*/
class OrFilter extends AndFilter
{
......
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