PHP Class Cake\ElasticSearch\FilterBuilder

Show file Open project: cakephp/elastic-search

Public Methods

Method Description
__call ( string $method, array $args ) : Elastica\Filter\AbstractFilter Helps calling the and() and or() methods transparently.
and_ ( ) @codingStandardsIgnoreStart
between ( string $field, mixed $from, mixed $to ) : Elastica\Filter\Range Returns a Range filter object setup to filter documents having the field between a from and a to value
bool ( ) : Elastica\Filter\BoolFilter Returns a bool filter that can be chained with the addMust(), addShould() and addMustNot() methods.
exists ( string $field ) : Elastica\Filter\Exists Returns an Exists filter object setup to filter documents having a property present or not set to null.
geoBoundingBox ( string $field, array | string $topLeft, array | string $bottomRight ) : Elastica\Filter\GeoBoundingBox Returns a GeoBoundingBox filter object setup to filter documents having a property bound by two coordinates.
geoDistance ( string $field, array | string $location, string $distance ) : Elastica\Filter\GeoDistance Returns an GeoDistance filter object setup to filter documents having a property in the radius distance of a coordinate.
geoDistanceRange ( string $field, array | string $location, string $from, string $to ) : Elastica\Filter\GeoDistanceRange Returns an GeoDistanceRange filter object setup to filter documents having a property in between two distance radius from a location coordinate.
geoHashCell ( string $field, string | array $location, integer | string $precision, boolean $neighbors = false ) : Elastica\Filter\GeohashCell Returns an GeohashCell filter object setup to filter documents having a property enclosed inside the specified geohash in teh give precision.
geoPolygon ( string $field, array $geoPoints ) : Elastica\Filter\GeoPolygon Returns an GeoPolygon filter object setup to filter documents having a property enclosed in the polygon induced by the passed geo points.
geoShape ( string $field, array $geoPoints, string $type = 'envelope' ) : Elastica\Filter\GeoShapeProvided Returns an GeoShapeProvided filter object setup to filter documents having a property enclosed in the specified geometrical shape type.
geoShapeIndex ( string $field, string $id, string $type, string $index = 'shapes', string $path = 'shape' ) : Elastica\Filter\GeoShapePreIndexed Returns an GeoShapePreIndex filter object setup to filter documents having a property enclosed in the specified geometrical shape type.
gt ( string $field, mixed $value ) : Elastica\Filter\Range Returns a Range filter object setup to filter documents having the field greater than the provided value.
gte ( string $field, mixed $value ) : Elastica\Filter\Range Returns a Range filter object setup to filter documents having the field greater than or equal the provided value.
hasChild ( string | Query | Elastica\Filter\AbstractFilter $query, string $type ) : Elastica\Filter\HasChild Accepts a query and the child type to run against, and results in parent documents that have child docs matching the query.
hasParent ( string | Query | Elastica\Filter\AbstractFilter $query, string $type ) : Elastica\Filter\HasParent Filters by child documents having parent documents matching the query
ids ( array $ids = [], string | array $type = null ) : Elastica\Filter\Ids Filters documents that only have the provided ids.
indices ( array $indices, Elastica\Filter\AbstractFilter $match, Elastica\Filter\AbstractFilter $noMatch ) : Elastica\Filter\Indices The indices filter can be used when executed across multiple indices, allowing you to have a filter that is only applied when executed on an index matching a specific list of indices, and another filter that executes when it is executed on an index that does not match the listed indices.
limit ( integer $limit ) : Elastica\Filter\Limit Limits the number of documents (per shard) to execute on.
lt ( string $field, mixed $value ) : Elastica\Filter\Range Returns a Range filter object setup to filter documents having the field smaller than the provided value.
lte ( string $field, mixed $value ) : Elastica\Filter\Range Returns a Range filter object setup to filter documents having the field smaller or equals than the provided value.
matchAll ( ) : Elastica\Filter\MatchAll A filter that returns all documents.
missing ( string $field = '' ) : Elastica\Filter\Missing Returns a Missing filter object setup to filter documents not having a property present or not null.
nested ( string $path, Elastica\Query\AbstractQuery | Elastica\Filter\AbstractFilter $filter ) : Elastica\Filter\Nested Returns a Nested filter object setup to filter sub documents by a path.
not ( Elastica\Filter\AbstractFilter $filter ) : Elastica\Filter\BoolNot Returns a BoolNot filter that is typically ussed to negate another filter expression
or_ ( ) @codingStandardsIgnoreStart
parse ( array | Elastica\Filter\AbstractFilter $conditions ) : array Converts an array into a single array of filter objects
prefix ( string $field, string $prefix ) : Elastica\Filter\Prefix Returns a Prefix filter to filter documents that have fields containing terms with a specified prefix
query ( array | Elastica\Query\AbstractQuery $query ) : Elastica\Filter\Query Returns a Query filter that Wraps any query to be used as a filter.
range ( string $field, array $args ) : Elastica\Filter\Range Returns a Range filter object setup to filter documents having the field greater than the provided values.
regexp ( string $field, string $regexp, array $options = [] ) : Elastica\Filter\Regexp Returns a Regexp filter to filter documents based on a regular expression.
script ( string $script ) : Elastica\Filter\Regexp Returns a Script filter object that allows to filter based on the return value of a script.
term ( string $field, string $value ) : Elastica\Filter\Term Returns a Term filter object that filters documents that have fields containing a term.
terms ( string $field, array $values ) : Elastica\Filter\Terms Returns a Terms filter object that filters documents that have fields containing some terms.
type ( string $type ) : Elastica\Filter\Type Returns a Type filter object that filters documents matching the provided document/mapping type.

Protected Methods

Method Description
_parseFilter ( string $field, mixed $value ) : Elastica\Filter\AbstractFilter Parses a field name containing an operator into a Filter object.

Method Details

__call() public method

Helps calling the and() and or() methods transparently.
public __call ( string $method, array $args ) : Elastica\Filter\AbstractFilter
$method string The method name.
$args array The argumemts to pass to the method.
return Elastica\Filter\AbstractFilter

_parseFilter() protected method

Parses a field name containing an operator into a Filter object.
protected _parseFilter ( string $field, mixed $value ) : Elastica\Filter\AbstractFilter
$field string The filed name containing the operator
$value mixed The value to pass to the filter
return Elastica\Filter\AbstractFilter

and_() public method

@codingStandardsIgnoreStart
public and_ ( )

between() public method

Returns a Range filter object setup to filter documents having the field between a from and a to value
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-filter.html
public between ( string $field, mixed $from, mixed $to ) : Elastica\Filter\Range
$field string The field to filter by.
$from mixed The lower bound value.
$to mixed The upper bound value.
return Elastica\Filter\Range

bool() public method

Returns a bool filter that can be chained with the addMust(), addShould() and addMustNot() methods.
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-filter.html
public bool ( ) : Elastica\Filter\BoolFilter
return Elastica\Filter\BoolFilter

exists() public method

Returns an Exists filter object setup to filter documents having a property present or not set to null.
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-filter.html
public exists ( string $field ) : Elastica\Filter\Exists
$field string The field to check for existance.
return Elastica\Filter\Exists

geoBoundingBox() public method

### Example: {{{ $filter = $builder->geoBoundingBox('location', [40.73, -74.1], [40.01, -71.12]); $filter = $builder->geoBoundingBox( 'location', ['lat => 40.73, 'lon' => -74.1], ['lat => 40.01, 'lon' => -71.12] ); $filter = $builder->geoBoundingBox('location', 'dr5r9ydj2y73', 'drj7teegpus6'); }}}
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-bounding-box-filter.html
public geoBoundingBox ( string $field, array | string $topLeft, array | string $bottomRight ) : Elastica\Filter\GeoBoundingBox
$field string The field to compare.
$topLeft array | string The top left coordinate.
$bottomRight array | string The bottom right coordinate.
return Elastica\Filter\GeoBoundingBox

geoDistance() public method

### Example: {{{ $filter = $builder->geoDistance('location', [40.73, -74.1], '10km'); $filter = $builder->geoBoundingBox('location', 'dr5r9ydj2y73', '5km'); }}}
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-range-filter.html
public geoDistance ( string $field, array | string $location, string $distance ) : Elastica\Filter\GeoDistance
$field string The field to compare.
$location array | string The coordinate from which to compare.
$distance string The distance radius.
return Elastica\Filter\GeoDistance

geoDistanceRange() public method

### Example: {{{ $filter = $builder->geoDistanceRange('location', [40.73, -74.1], '10km', '20km'); $filter = $builder->geoDistanceRange('location', 'dr5r9ydj2y73', '5km', '10km'); }}}
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-filter.html
public geoDistanceRange ( string $field, array | string $location, string $from, string $to ) : Elastica\Filter\GeoDistanceRange
$field string The field to compare.
$location array | string The coordinate from which to compare.
$from string The initial distance radius.
$to string The ending distance radius.
return Elastica\Filter\GeoDistanceRange

geoHashCell() public method

### Example: {{{ $filter = $builder->geoHashCell('location', [40, -70], 3); }}}
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geohash-cell-filter.html
public geoHashCell ( string $field, string | array $location, integer | string $precision, boolean $neighbors = false ) : Elastica\Filter\GeohashCell
$field string The field to compare.
$location string | array Location as coordinates array or geohash string.
$precision integer | string Length of geohash prefix or distance (3, or "50m")
$neighbors boolean If true, filters cells next to the given cell.
return Elastica\Filter\GeohashCell

geoPolygon() public method

### Example: {{{ $filter = $builder->geoPolygon('location', [ ['lat' => 40, 'lon' => -70], ['lat' => 30, 'lon' => -80], ['lat' => 20, 'lon' => -90], ]); $filter = $builder->geoPolygon('location', [ 'drn5x1g8cu2y', ['lat' => 30, 'lon' => -80], '20, -90', ]); }}}
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-polygon-filter.html
public geoPolygon ( string $field, array $geoPoints ) : Elastica\Filter\GeoPolygon
$field string The field to compare.
$geoPoints array List of geo points that form the polygon
return Elastica\Filter\GeoPolygon

geoShape() public method

### Example: {{{ $filter = $builder->geoShape('location', [[13.0, 53.0], [14.0, 52.0]], 'envelope'); $filter = $builder->geoShape('location', [ [[-77.03653, 38.897676], [-77.009051, 38.889939]], 'linestring' ]); }}} You can read about the supported shapes and how they are created here: http://www.elastic.co/guide/en/elasticsearch/reference/1.x/mapping-geo-shape-type.html
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-filter.html
public geoShape ( string $field, array $geoPoints, string $type = 'envelope' ) : Elastica\Filter\GeoShapeProvided
$field string The field to compare.
$geoPoints array List of geo points that form the shape.
$type string The shape type to use (envelope, linestring, polygon, multipolygon...)
return Elastica\Filter\GeoShapeProvided

geoShapeIndex() public method

### Example: {{{ $filter = $builder->geoShapeIndex('location', 'DEU', 'countries', 'shapes', 'location'); }}}
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-filter.html
public geoShapeIndex ( string $field, string $id, string $type, string $index = 'shapes', string $path = 'shape' ) : Elastica\Filter\GeoShapePreIndexed
$field string The field to compare.
$id string The ID of the document containing the pre-indexed shape.
$type string Index type where the pre-indexed shape is.
$index string Name of the index where the pre-indexed shape is.
$path string The field specified as path containing the pre-indexed shape.
return Elastica\Filter\GeoShapePreIndexed

gt() public method

Returns a Range filter object setup to filter documents having the field greater than the provided value.
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-filter.html
public gt ( string $field, mixed $value ) : Elastica\Filter\Range
$field string The field to filter by.
$value mixed The value to compare with.
return Elastica\Filter\Range

gte() public method

Returns a Range filter object setup to filter documents having the field greater than or equal the provided value.
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-filter.html
public gte ( string $field, mixed $value ) : Elastica\Filter\Range
$field string The field to filter by.
$value mixed The value to compare with.
return Elastica\Filter\Range

hasChild() public method

Accepts a query and the child type to run against, and results in parent documents that have child docs matching the query.
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-child-filter.html
public hasChild ( string | Query | Elastica\Filter\AbstractFilter $query, string $type ) : Elastica\Filter\HasChild
$query string | Elastica\Query | Elastica\Filter\AbstractFilter The filtering conditions.
$type string The child type to query against.
return Elastica\Filter\HasChild

hasParent() public method

Filters by child documents having parent documents matching the query
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-parent-filter.html
public hasParent ( string | Query | Elastica\Filter\AbstractFilter $query, string $type ) : Elastica\Filter\HasParent
$query string | Elastica\Query | Elastica\Filter\AbstractFilter The filtering conditions.
$type string The parent type to query against.
return Elastica\Filter\HasParent

ids() public method

Filters documents that only have the provided ids.
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-ids-filter.html
public ids ( array $ids = [], string | array $type = null ) : Elastica\Filter\Ids
$ids array The list of ids to filter by.
$type string | array A single or multiple types in which the ids should be searched.
return Elastica\Filter\Ids

indices() public method

### Example: {{{ $builder->indices( ['index1', 'index2'], $builder->term('user', 'jhon'), $builder->term('tag', 'wow') ); }}}
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-indices-filter.html
public indices ( array $indices, Elastica\Filter\AbstractFilter $match, Elastica\Filter\AbstractFilter $noMatch ) : Elastica\Filter\Indices
$indices array The indices where to apply the filter.
$match Elastica\Filter\AbstractFilter Filter which will be applied to docs in the specified indices.
$noMatch Elastica\Filter\AbstractFilter Filter to apply to documents not present in the specified indices.
return Elastica\Filter\Indices

limit() public method

Limits the number of documents (per shard) to execute on.
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-limit-filter.html
public limit ( integer $limit ) : Elastica\Filter\Limit
$limit integer The maximum number of documents to filter.
return Elastica\Filter\Limit

lt() public method

Returns a Range filter object setup to filter documents having the field smaller than the provided value.
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-filter.html
public lt ( string $field, mixed $value ) : Elastica\Filter\Range
$field string The field to filter by.
$value mixed The value to compare with.
return Elastica\Filter\Range

lte() public method

Returns a Range filter object setup to filter documents having the field smaller or equals than the provided value.
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-filter.html
public lte ( string $field, mixed $value ) : Elastica\Filter\Range
$field string The field to filter by.
$value mixed The value to compare with.
return Elastica\Filter\Range

matchAll() public method

A filter that returns all documents.
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-all-filter.html
public matchAll ( ) : Elastica\Filter\MatchAll
return Elastica\Filter\MatchAll

missing() public method

Returns a Missing filter object setup to filter documents not having a property present or not null.
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-filter.html
public missing ( string $field = '' ) : Elastica\Filter\Missing
$field string The field to check for existance.
return Elastica\Filter\Missing

nested() public method

### Example: {{{ $builder->nested('comments', $builder->term('author', 'mark')); }}} Or using a query as filter: {{{ $builder->nested('comments', new \Elastica\Query\SimpleQueryString('awesome')); }}}
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-filter.html
public nested ( string $path, Elastica\Query\AbstractQuery | Elastica\Filter\AbstractFilter $filter ) : Elastica\Filter\Nested
$path string A dot separated string denoting the path to the property to filter.
$filter Elastica\Query\AbstractQuery | Elastica\Filter\AbstractFilter The filtering conditions.
return Elastica\Filter\Nested

not() public method

Returns a BoolNot filter that is typically ussed to negate another filter expression
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-not-filter.html
public not ( Elastica\Filter\AbstractFilter $filter ) : Elastica\Filter\BoolNot
$filter Elastica\Filter\AbstractFilter The filter to negate
return Elastica\Filter\BoolNot

or_() public method

@codingStandardsIgnoreStart
public or_ ( )

parse() public method

### Parsing a single array: {{{ $filter = $builder->parse([ 'name' => 'mark', 'age <=' => 35 ]); Equivalent to: $filter = [ $builder->term('name', 'mark'), $builder->lte('age', 35) ]; }}} ### Creating "or" conditions: {{{ $filter = $builder->parse([ 'or' => [ 'name' => 'mark', 'age <=' => 35 ] ]); Equivalent to: $filter = [$builder->or( $builder->term('name', 'mark'), $builder->lte('age', 35) )]; }}} ### Negating conditions: {{{ $filter = $builder->parse([ 'not' => [ 'name' => 'mark', 'age <=' => 35 ] ]); Equivalent to: $filter = [$builder->not( $builder->and( $builder->term('name', 'mark'), $builder->lte('age', 35) ) )]; }}} ### Checking for field existance {{{ $filter = $builder->parse([ 'name is' => null, 'age is not' => null ]); Equivalent to: $filter = [ $builder->missing('name'), $builder->exists('age') ]; }}} ### Checking if a value is in a list of terms {{{ $filter = $builder->parse([ 'name in' => ['jose', 'mark'] ]); Equivalent to: $filter = [$builder->terms('name', ['jose', 'mark'])] }}} The list of supported operators is: <, >, <=, >=, in, not in, is, is not, !=
public parse ( array | Elastica\Filter\AbstractFilter $conditions ) : array
$conditions array | Elastica\Filter\AbstractFilter The list of conditions to parse.
return array

prefix() public method

Returns a Prefix filter to filter documents that have fields containing terms with a specified prefix
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-prefix-filter.html
public prefix ( string $field, string $prefix ) : Elastica\Filter\Prefix
$field string The field to filter by.
$prefix string The prefix to check for.
return Elastica\Filter\Prefix

query() public method

### Example: {{{ $builder->query(new \Elastica\Query\SimpleQueryString('awesome OR great')); }}}
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-filter.html
public query ( array | Elastica\Query\AbstractQuery $query ) : Elastica\Filter\Query
$query array | Elastica\Query\AbstractQuery The Query to wrap as a filter
return Elastica\Filter\Query

range() public method

The $args array accepts the following keys: - gte: greater than or equal - gt: greater than - lte: less than or equal - lt: less than
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-filter.html
public range ( string $field, array $args ) : Elastica\Filter\Range
$field string The field to filter by.
$args array An array describing the search range
return Elastica\Filter\Range

regexp() public method

### Example: {{{ $builder->regexp('name.first', 'ma.*'); }}}
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-filter.html
public regexp ( string $field, string $regexp, array $options = [] ) : Elastica\Filter\Regexp
$field string The field to filter by.
$regexp string The regular expression.
$options array Regultar expression flags or options.
return Elastica\Filter\Regexp

script() public method

### Example: {{{ $builder->script("doc['price'].value > 1"); }}}
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-filter.html
public script ( string $script ) : Elastica\Filter\Regexp
$script string The script.
return Elastica\Filter\Regexp

term() public method

### Example: {{{ $builder->term('user.name', 'jose'); }}}
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-filter.html
public term ( string $field, string $value ) : Elastica\Filter\Term
$field string The field to filter by.
$value string The term to find in field.
return Elastica\Filter\Term

terms() public method

### Example: {{{ $builder->terms('user.name', ['jose', 'mark']); }}}
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-filter.html
public terms ( string $field, array $values ) : Elastica\Filter\Terms
$field string The field to filter by.
$values array The list of terms to find in field.
return Elastica\Filter\Terms

type() public method

### Example: {{{ $builder->type('products'); }}}
See also: http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-type-filter.html
public type ( string $type ) : Elastica\Filter\Type
$type string The type name
return Elastica\Filter\Type