diff --git a/CHANGELOG.md b/CHANGELOG.md index 340e0e4dca6e9b3a08a338ac6a0869eb9b4793a5..9796b503482c762a35f631fe9fb449d1b237f221 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ v2.0.0 (2016-x) --- - [BC break] Aggregation name is not prefixed anymore +- [BC break] Removed all filters and filtered query v1.1.1 (2016-01-26) --- diff --git a/README.md b/README.md index 4e6aa41119b177a9c3bb593837a9a75605983ed1..db17faf4c42a84965144d4501ef9a7c8012707b9 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ If you have any questions, don't hesitate to ask them on [](https://packagist.org/packages/ongr/elasticsearch-dsl) [](https://scrutinizer-ci.com/g/ongr-io/ElasticsearchDSL/?branch=master) +__This component requires Elasticsearch 2.0 or newer.__ ## Documentation @@ -21,8 +22,8 @@ If you have any questions, don't hesitate to ask them on [: -``` -composer require ongr/elasticsearch-dsl "~1.0" +```bash +$ composer require ongr/elasticsearch-dsl ``` ### Search @@ -33,8 +34,8 @@ If you dont want to use Symfony or Elasticsearch bundle, no worries, you can use Install `elasticsearch-php`: -``` -composer require "elasticsearch/elasticsearch": "~2.0" +```bash +$ composer require elasticsearch/elasticsearch ``` Create search: diff --git a/docs/Aggregation/Filter.md b/docs/Aggregation/Filter.md index 96a2dbb86ee48fd1d027221c8268d7e3d6e0082a..62d5c7b220bdfb06a8d520118d85ee8f6f074854 100644 --- a/docs/Aggregation/Filter.md +++ b/docs/Aggregation/Filter.md @@ -24,7 +24,7 @@ context to a specific set of documents. And now the query via DSL: ```php -$termFilter = new TermFilter('color', 'red'); +$termFilter = new TermQuery('color', 'red'); $avgAggregation = new AvgAggregation('avg_price', 'price'); $filterAggregation = new FilterAggregation('grades_stats', $termFilter); diff --git a/docs/Aggregation/Filters.md b/docs/Aggregation/Filters.md index b36fecc13f3c44bf669d30bf608d15b4b2e534f5..26b7c4dab714917a5b5aae7ca52d65822fc7cd84 100644 --- a/docs/Aggregation/Filters.md +++ b/docs/Aggregation/Filters.md @@ -37,8 +37,8 @@ in exception. And now the query via DSL: ```php -$errorTermFilter = new TermFilter('body', 'error'); -$warningTermFilter = new TermFilter('body', 'warning'); +$errorTermFilter = new TermQuery('body', 'error'); +$warningTermFilter = new TermQuery('body', 'warning'); $histogramAggregation = new HistogramAggregation('monthly', 'timestamp'); $histogramAggregation->setInterval('1M'); @@ -86,8 +86,8 @@ $queryArray = $search->toArray(); And now the query via DSL: ```php -$errorTermFilter = new TermFilter('body', 'error'); -$warningTermFilter = new TermFilter('body', 'warning'); +$errorTermFilter = new TermQuery('body', 'error'); +$warningTermFilter = new TermQuery('body', 'warning'); $histogramAggregation = new HistogramAggregation('monthly', 'timestamp'); $histogramAggregation->setInterval('1M'); diff --git a/docs/Filter/And.md b/docs/Filter/And.md deleted file mode 100644 index b514f8ed7424e50c2ca8ed6c9b09c02a0bc15042..0000000000000000000000000000000000000000 --- a/docs/Filter/And.md +++ /dev/null @@ -1,51 +0,0 @@ -# And Filter - -> More info about and filter is in the [official elasticsearch docs][1] - -A filter that matches documents using the AND boolean operator on other filters. -Can be placed within queries that accept a filter. - -## Simple example - -```JSON -{ - "filtered" : { - "query" : { - "term" : { "name.first" : "shay" } - }, - "filter" : { - "and" : [ - { - "range" : { - "postDate" : { - "from" : "2010-03-01", - "to" : "2010-04-01" - } - } - }, - { - "prefix" : { "name.second" : "ba" } - } - ] - } - } -} -``` - -And now the query via DSL: - -```php -$rangeFilter = new RangeFilter('postDate', ['from' => '2010-03-01', 'to' => '2010-04-01']); -$prefixFilter = new PrefixFilter('name.second', 'ba'); -$andFilter = new AndFilter([$rangeFilter, $prefixFilter]); - -$termQuery = new TermQuery('name.first', 'shay'); - -$search = new Search(); -$search->addQuery($termQuery); -$search->addFilter($andFilter); - -$queryArray = $search->toArray(); -``` - -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-and-filter.html diff --git a/docs/Filter/Bool.md b/docs/Filter/Bool.md deleted file mode 100644 index a9efc2b63837ccae450311693f11047f2340be83..0000000000000000000000000000000000000000 --- a/docs/Filter/Bool.md +++ /dev/null @@ -1,96 +0,0 @@ -# Bool Filter - -> More info about filter query is in the [official elasticsearch docs][1] - -A filter that matches documents matching boolean combinations of other queries. Similar in concept to -[Boolean query][2], except that the clauses are other filters. - -To create a bool filter unlike other queries you don't have to create `BoolFilter` object. Just add queries to the -search object and it will form bool filter automatically. - -Lets take an example to write a bool query with Elasticsearch DSL. - -```JSON -{ - "filtered" : { - "query" : { - "queryString" : { - "default_field" : "message", - "query" : "elasticsearch" - } - }, - "filter" : { - "bool" : { - "must" : { - "term" : { "tag" : "wow" } - }, - "must_not" : { - "range" : { - "age" : { "gte" : 10, "lt" : 20 } - } - }, - "should" : [ - { - "term" : { "tag" : "sometag" } - }, - { - "term" : { "tag" : "sometagtag" } - } - ] - } - } - } -} -``` - -And now the query via DSL: - -```php -$queryStringQuery = new QueryStringQuery('elasticsearch', ['default_field' => 'message']); - -$termFilter1 = new TermFilter('tag', 'wow'); -$rangeFilter = new RangeFilter('age', ['gte' => 10, 'lt' => 20]); -$termFilter2 = new TermFilter('tag', 'sometag'); -$termFilter3 = new TermFilter('tag', 'sometagtag'); - -$search = new Search(); -$search->addQuery($queryStringQuery); -$search->addFilter($termFilter1); -$search->addFilter($rangeFilter, BoolFilter::MUST_NOT); -$search->addFilter($termFilter2, BoolFilter::SHOULD); -$search->addFilter($termFilter3, BoolFilter::SHOULD); - -$queryArray = $search->toArray(); -``` - -There is also an exception due adding filters to the search. If you add only one filter without type -it will form simple query. e.g. lets try to create match all filter. - -```php -$matchAllFilter = new MatchAllFilter(); - -$search = new Search(); -$search->addFilter($matchAllFilter); - -$queryArray = $search->toArray(); -``` - -You will get this query: -```JSON -{ - "query": { - "filtered": { - "filter": { - "match_all": {} - } - } - } -} -``` - -> More info about `Search` look in the [How to search](../HowTo/HowToSearch.md) chapter. - - - -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-filter.html -[2]: ../Query/Bool.md diff --git a/docs/Filter/Exists.md b/docs/Filter/Exists.md deleted file mode 100644 index c54434e3994e396e84ed630a481b1410f371587c..0000000000000000000000000000000000000000 --- a/docs/Filter/Exists.md +++ /dev/null @@ -1,31 +0,0 @@ -# Exists Filter - -> More info about exists filter is in the [official elasticsearch docs][1] - -Returns documents that have at least one non-null value in the original field. - -## Simple example - -```JSON -{ - "constant_score" : { - "filter" : { - "exists" : { "field" : "user" } - } - } -} -``` - -And now the query via DSL: - -```php -$existsFilter = new ExistsFilter('user'); -$constantScoreQuery = new ConstantScoreQuery($existsFilter); - -$search = new Search(); -$search->addQuery($constantScoreQuery); - -$queryArray = $search->toArray(); -``` - -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-filter.html diff --git a/docs/Filter/GeoBoundingBox.md b/docs/Filter/GeoBoundingBox.md deleted file mode 100644 index 2d3e23edc4d964286a21118ae59edd67c9754ad9..0000000000000000000000000000000000000000 --- a/docs/Filter/GeoBoundingBox.md +++ /dev/null @@ -1,90 +0,0 @@ -# Geo Bounding Box Filter - -> More info about geo bounding box filter is in the [official elasticsearch docs][1] - -A filter allowing to filter hits based on a point location using a bounding box. - -## Simple example - -```JSON -{ - "filtered" : { - "query" : { - "match_all" : {} - }, - "filter" : { - "geo_bounding_box" : { - "pin.location" : { - "top_left" : { - "lat" : 40.73, - "lon" : -74.1 - }, - "bottom_right" : { - "lat" : 40.01, - "lon" : -71.12 - } - } - } - } - } -} -``` - -And now the query via DSL: - -```php -$geoBoundingBoxFilter = new GeoBoundingBoxFilter( - 'pin.location', - [ - ['lat' => 40.73, 'lon' => -74.1], - ['lat' => 40.01, 'lon' => -74.12], - ] -); - -$search = new Search(); -$search->addFilter($geoBoundingBoxFilter); - -$queryArray = $search->toArray(); -``` - -Other format - -```JSON -"filtered" : { - "query" : { - "match_all" : {} - }, - "filter" : { - "geo_bounding_box" : { - "pin.location" : { - "top" : -74.1, - "left" : 40.73, - "bottom" : -71.12, - "right" : 40.01 - } - } - } -} -``` - -In DSL - -```php -$geoBoundingBoxFilter = new GeoBoundingBoxFilter( - 'pin.location', - [ - -74.1, - 40.73, - -71.12, - 40.01, - ] -); - -$search = new Search(); -$search->addFilter($geoBoundingBoxFilter); - -$queryArray = $search->toArray(); -``` - - -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-bounding-box-filter.html diff --git a/docs/Filter/GeoDistance.md b/docs/Filter/GeoDistance.md deleted file mode 100644 index 8c2ec11f36763c649b3176cc70f1db8edcd4ae7e..0000000000000000000000000000000000000000 --- a/docs/Filter/GeoDistance.md +++ /dev/null @@ -1,43 +0,0 @@ -# Geo Distance Filter - -> More info about geo distance filter is in the [official elasticsearch docs][1] - -Filters documents that include only hits that exists within a specific distance from a geo point. - -## Simple example - -```JSON -{ - "filtered" : { - "query" : { - "match_all" : {} - }, - "filter" : { - "geo_distance" : { - "distance" : "200km", - "pin.location" : { - "lat" : 40, - "lon" : -70 - } - } - } - } -} -``` - -And now the query via DSL: - -```php -$geoDistanceFilter = new GeoDistanceFilter( - 'pin.location', - '200km', - ['lat' => 40, 'lon' => -70] -); - -$search = new Search(); -$search->addFilter($geoDistanceFilter); - -$queryArray = $search->toArray(); -``` - -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-filter.html diff --git a/docs/Filter/GeoDistanceRange.md b/docs/Filter/GeoDistanceRange.md deleted file mode 100644 index ccb692c0e7b95f42dc2b18de1ba08ccfbd921a83..0000000000000000000000000000000000000000 --- a/docs/Filter/GeoDistanceRange.md +++ /dev/null @@ -1,45 +0,0 @@ -# Geo Distance Range Filter - -> More info about geo distance range filter is in the [official elasticsearch docs][1] - -Filters documents that exists within a range from a specific point. - -## Simple example - -```JSON -{ - "filtered" : { - "query" : { - "match_all" : {} - }, - "filter" : { - "geo_distance_range" : { - "from" : "200km", - "to" : "400km", - "pin.location" : { - "lat" : 40, - "lon" : -70 - } - } - } - } -} -``` - -And now the query via DSL: - -```php -$geoDistanceRangeFilter = new GeoDistanceRangeFilter( - 'pin.location', - ['from' => '200km', 'to' => '400km'], - ['lat' => 40, 'lon' => -70] -); - -$search = new Search(); -$search->addFilter($geoDistanceRangeFilter); - -$queryArray = $search->toArray(); -``` - -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-range-filter.html - diff --git a/docs/Filter/GeoPolygon.md b/docs/Filter/GeoPolygon.md deleted file mode 100644 index 98631f16fc8f573c8a65c6c0c09da38f90500dbb..0000000000000000000000000000000000000000 --- a/docs/Filter/GeoPolygon.md +++ /dev/null @@ -1,48 +0,0 @@ -# Geo Polygon Filter - -> More info about geo polygon range filter is in the [official elasticsearch docs][1] - -A filter allowing to include hits that only fall within a polygon of points. - -## Simple example - -```JSON -{ - "filtered" : { - "query" : { - "match_all" : {} - }, - "filter" : { - "geo_polygon" : { - "person.location" : { - "points" : [ - {"lat" : 40, "lon" : -70}, - {"lat" : 30, "lon" : -80}, - {"lat" : 20, "lon" : -90} - ] - } - } - } - } -} -``` - -And now the query via DSL: - -```php -$geoPolygonFilter = new GeoPolygonFilter( - 'person.location', - [ - ['lat' => 40, 'lon' => -70], - ['lat' => 30, 'lon' => -80], - ['lat' => 20, 'lon' => -90], - ] -); - -$search = new Search(); -$search->addFilter($geoPolygonFilter); - -$queryArray = $search->toArray(); -``` - -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-polygon-filter.html diff --git a/docs/Filter/GeoShape.md b/docs/Filter/GeoShape.md deleted file mode 100644 index e44d81696d08d5b7d9657ffa07c849a3340b055f..0000000000000000000000000000000000000000 --- a/docs/Filter/GeoShape.md +++ /dev/null @@ -1,86 +0,0 @@ -# Geo Shape Filter - -> More info about geo shape filter is in the [official elasticsearch docs][1] - -Filter documents indexed using the geo shape type. - -## Simple example - -```JSON -{ - "query":{ - "filtered": { - "query": { - "match_all": {} - }, - "filter": { - "geo_shape": { - "location": { - "shape": { - "type": "envelope", - "coordinates" : [[13.0, 53.0], [14.0, 52.0]] - } - } - } - } - } - } -} -``` - -And now the query via DSL: - -```php -$geoShapeFilter = new GeoShapeFilter(); -$geoShapeFilter->addShape('location', 'envelope', [[13.0, 53.0], [14.0, 52.0]]); - -$search = new Search(); -$search->addFilter($geoShapeFilter); - -$queryArray = $search->toArray(); -``` - -## Pre Indexed Shape - -```JSON -{ - "filtered": { - "query": { - "match_all": {} - }, - "filter": { - "geo_shape": { - "location": { - "indexed_shape": { - "id": "DEU", - "type": "countries", - "index": "shapes", - "path": "location" - } - } - } - } - } -} -``` - -And now the query via DSL: - -```php -$geoShapeFilter = new GeoShapeFilter(); -$geoShapeFilter->addPreIndexedShape( - 'location', - 'DEU', - 'countries', - 'shapes', - 'location' -); - -$search = new Search(); -$search->addFilter($geoShapeFilter); - -$queryArray = $search->toArray(); -``` - - -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-filter.html diff --git a/docs/Filter/GeohashCell.md b/docs/Filter/GeohashCell.md deleted file mode 100644 index 25edda7827fe427d6621ca12b990bc1fa25c0dbf..0000000000000000000000000000000000000000 --- a/docs/Filter/GeohashCell.md +++ /dev/null @@ -1,51 +0,0 @@ -# Geohash Cell Filter - -> More info about geohash cell filter is in the [official elasticsearch docs][1] - -The geohash cell filter provides access to a hierarchy of geohashes. -By defining a geohash cell, only geopoints within this cell will match this filter. - -## Simple example - -```JSON -{ - "filtered" : { - "query" : { - "match_all" : {} - }, - "filter" : { - "geohash_cell": { - "pin": { - "lat": 13.4080, - "lon": 52.5186 - }, - "precision": 3, - "neighbors": true - } - } - } -} -``` - -And now the query via DSL: - -```php -$geohashCellFilter = new GeohashCellFilter( - 'pin', - [ - 'lat' => 13.4080, - 'lon' => 52.5186, - ], - [ - 'precision' => 3, - 'neighbors' => true, - ] -); - -$search = new Search(); -$search->addFilter($geohashCellFilter); - -$queryArray = $search->toArray(); -``` - -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geohash-cell-filter.html diff --git a/docs/Filter/HasChild.md b/docs/Filter/HasChild.md deleted file mode 100644 index 7ea66912261a7024dcad30b05bbc5b0625e37599..0000000000000000000000000000000000000000 --- a/docs/Filter/HasChild.md +++ /dev/null @@ -1,38 +0,0 @@ -# Has Child Filter - -> More info about has child filter is in the [official elasticsearch docs][1] - -The has child filter accepts a query and the child type to run against, -and results in parent documents that have child docs matching the query. - -## Simple example - -```JSON -{ - "has_child" : { - "type" : "blog_tag", - "query" : { - "term" : { - "tag" : "something" - } - } - } -} -``` - -And now the query via DSL: - -```php -$termQuery = new TermQuery('tag', 'something'); -$hasChildFilter = new HasChildFilter( - 'blog_tag', - $termQuery -); - -$search = new Search(); -$search->addFilter($hasChildFilter); - -$queryArray = $search->toArray(); -``` - -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-child-filter.html diff --git a/docs/Filter/HasParent.md b/docs/Filter/HasParent.md deleted file mode 100644 index 53bd7fa2454a86f715c53f4c20538e2b0874eed2..0000000000000000000000000000000000000000 --- a/docs/Filter/HasParent.md +++ /dev/null @@ -1,39 +0,0 @@ -# Has Parent Filter - -> More info about has parent filter is in the [official elasticsearch docs][1] - -The has parent filter accepts a query and a parent type. -The query is executed in the parent document space, which is specified by the parent type. -This filter returns child documents which associated parents have matched. - -## Simple example - -```JSON -{ - "has_child" : { - "type" : "blog_tag", - "query" : { - "term" : { - "tag" : "something" - } - } - } -} -``` - -And now the query via DSL: - -```php -$termQuery = new TermQuery('tag', 'something'); -$hasParentFilter = new HasParentFilter( - 'blog', - $termQuery -); - -$search = new Search(); -$search->addFilter($hasParentFilter); - -$queryArray = $search->toArray(); -``` - -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-parent-filter.html diff --git a/docs/Filter/Ids.md b/docs/Filter/Ids.md deleted file mode 100644 index e2bcfb6ed8e2dc51b4cb1589546ae4c6e6bb733c..0000000000000000000000000000000000000000 --- a/docs/Filter/Ids.md +++ /dev/null @@ -1,32 +0,0 @@ -# Ids Filter - -> More info about ids filter is in the [official elasticsearch docs][1] - -Filters documents that only have the provided ids. - -## Simple example - -```JSON -{ - "ids" : { - "type" : "my_type", - "values" : ["1", "4", "100"] - } -} -``` - -And now the query via DSL: - -```php -$idsFilters = new IdsFilter( - ['1', '4', '100'], - ['type' => 'my_type'] -); - -$search = new Search(); -$search->addFilter($idsFilters); - -$queryArray = $search->toArray(); -``` - -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-ids-filter.html diff --git a/docs/Filter/Indices.md b/docs/Filter/Indices.md deleted file mode 100644 index caacb11fd90617f103d5b1578cdc08caa8456143..0000000000000000000000000000000000000000 --- a/docs/Filter/Indices.md +++ /dev/null @@ -1,45 +0,0 @@ -# Indices Filter - -> More info about indices filter is in the [official elasticsearch docs][1] - -The indices filter can be used when executed across multiple indices, -allowing to have a filter that executes only when executed on an index -that matches a specific list of indices, and another filter that -executes when it is executed on an index that does not match the listed -indices. - -## Simple example - -```JSON -{ - "indices" : { - "indices" : ["index1", "index2"], - "filter" : { - "term" : { "tag" : "wow" } - }, - "no_match_filter" : { - "term" : { "tag" : "kow" } - } - } -} -``` - -And now the query via DSL: - -```php -$termFilter1 = new TermFilter('tag', 'wow'); -$termFilter2 = new TermFilter('tag', 'kow'); - -$indicesFilter = new IndicesFilter( - ['index1', 'index2'], - $termFilter1, - $termFilter2 -); - -$search = new Search(); -$search->addFilter($indicesFilter); - -$queryArray = $search->toArray(); -``` - -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-indices-filter.html diff --git a/docs/Filter/Limit.md b/docs/Filter/Limit.md deleted file mode 100644 index 567be0fb817ec5d15cc974492682782d3a1db4af..0000000000000000000000000000000000000000 --- a/docs/Filter/Limit.md +++ /dev/null @@ -1,35 +0,0 @@ -# Limit Filter - -> More info about limit filter is in the [official elasticsearch docs][1] - -A limit filter limits the number of documents (per shard) to execute on. - -## Simple example - -```JSON -{ - "filtered" : { - "filter" : { - "limit" : {"value" : 100} - }, - "query" : { - "term" : { "name.first" : "shay" } - } - } -} -``` - -And now the query via DSL: - -```php -$limitFilter = new LimitFilter(100); -$termQuery = new TermQuery('name.first', 'shay'); - -$filteredQuery = new FilteredQuery($termQuery, $limitFilter); - -$search = new Search(); -$search->addQuery($filteredQuery); -$queryArray = $search->toArray(); -``` - -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-limit-filter.html diff --git a/docs/Filter/MatchAll.md b/docs/Filter/MatchAll.md deleted file mode 100644 index 3d8d9ed61a78a765f033bf7f6a485f67347a271e..0000000000000000000000000000000000000000 --- a/docs/Filter/MatchAll.md +++ /dev/null @@ -1,28 +0,0 @@ -# Match All Filter - -> More info about match all filter is in the [official elasticsearch docs][1] - -A filter that matches on all documents. - -## Simple example - -```JSON -{ - "filter" : { - "match_all" : { } - } -} -``` - -And now the query via DSL: - -```php -$matchAllFilter = new MatchAllFilter(); - -$search = new Search(); -$search->addFilter($matchAllFilter); - -$queryArray = $search->toArray(); -``` - -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-indices-filter.html diff --git a/docs/Filter/Missing.md b/docs/Filter/Missing.md deleted file mode 100644 index f963111bac2932d739b85853bb209ec4748c6ae8..0000000000000000000000000000000000000000 --- a/docs/Filter/Missing.md +++ /dev/null @@ -1,28 +0,0 @@ -# Missing Filter - -> More info about missing filter is in the [official elasticsearch docs][1] - -Returns documents that have only null values or no value in the original field. - -## Simple example - -```JSON -{ - "filter" : { - "missing" : { "field" : "user" } - } -} -``` - -And now the query via DSL: - -```php -$missingFilter = new MissingFilter('user'); - -$search = new Search(); -$search->addFilter($missingFilter); - -$queryArray = $search->toArray(); -``` - -[1]: hhttps://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-missing-filter.html diff --git a/docs/Filter/Nested.md b/docs/Filter/Nested.md deleted file mode 100644 index 151ac121d296b0dbf45565347fad8213d323251a..0000000000000000000000000000000000000000 --- a/docs/Filter/Nested.md +++ /dev/null @@ -1,56 +0,0 @@ -# Nested Filter - -> More info about nested filter is in the [official elasticsearch docs][1] - -Nested filter allows to filter nested objects / documents (see nested mapping). -The filter is executed against the nested objects / documents as if they -were indexed as separate documents (they are, internally) and resulting -in the root parent doc (or parent nested mapping). - -## Simple example - -```JSON -{ - "filtered" : { - "query" : { "match_all" : {} }, - "filter" : { - "nested" : { - "path" : "obj1", - "filter" : { - "bool" : { - "must" : [ - { - "term" : {"obj1.name" : "blue"} - }, - { - "range" : {"obj1.count" : {"gt" : 5}} - } - ] - } - }, - "_cache" : true - } - } - } -} -``` - -And now the query via DSL: - -```php -$termFilter = new TermFilter('obj1.name', 'blue'); -$rangeFilter = new RangeFilter('obj1.count', ['gt' => 5]); - -$boolFilter = new BoolFilter(); -$boolFilter->add($termFilter); -$boolFilter->add($rangeFilter); - -$nestedFilter = new NestedFilter('obj1', $boolFilter, ['_cache' => true]); - -$search = new Search(); -$search->addFilter($nestedFilter); - -$queryArray = $search->toArray(); -``` - -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-filter.html diff --git a/docs/Filter/Not.md b/docs/Filter/Not.md deleted file mode 100644 index 9fc9697af7bb519e091593f41892755fa1bd6b82..0000000000000000000000000000000000000000 --- a/docs/Filter/Not.md +++ /dev/null @@ -1,50 +0,0 @@ -# Not Filter - -> More info about not filter is in the [official elasticsearch docs][1] - -A filter that filters out matched documents using a query. - -## Simple example - -```JSON -{ - "filtered" : { - "query" : { - "term" : { "name.first" : "shay" } - }, - "filter" : { - "not" : { - "range" : { - "postDate" : { - "from" : "2010-03-01", - "to" : "2010-04-01" - } - } - } - } - } -} -``` - -And now the query via DSL: - -```php -$rangeFilter = new RangeFilter( - 'postDate', - [ - 'from' => '2010-03-01', - 'to' => '2010-04-01', - ] -); - -$notFilter = new NotFilter($rangeFilter); - -$termQuery = new TermQuery('name.first', 'shay'); -$filteredQuery = new FilteredQuery($termQuery, $notFilter); - -$search = new Search(); -$search->addQuery($filteredQuery); -$queryArray = $search->toArray(); -``` - -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-not-filter.html diff --git a/docs/Filter/Or.md b/docs/Filter/Or.md deleted file mode 100644 index 34a666afa81e5c7033a0cbf43aa39f1522200755..0000000000000000000000000000000000000000 --- a/docs/Filter/Or.md +++ /dev/null @@ -1,49 +0,0 @@ -# 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. - -## Simple example - -```JSON -{ - "filtered" : { - "query" : { - "term" : { "name.first" : "shay" } - }, - "filter" : { - "or" : [ - { - "term" : { "name.second" : "banon" } - }, - { - "term" : { "name.nick" : "kimchy" } - } - ] - } - } -} -``` - -And now the query via DSL: - -```php -$termFilter1 = new TermFilter('name.second', 'banon'); -$termFilter2 = new TermFilter('name.nick', 'kimchy'); - -$orFilter = new OrFilter(); -$orFilter->add($termFilter1); -$orFilter->add($termFilter2); - -$termQuery = new TermQuery('name.first', 'shay'); -$filteredQuery = new FilteredQuery($termQuery, $orFilter); - -$search = new Search(); -$search->addQuery($filteredQuery); -$queryArray = $search->toArray(); -``` - -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-or-filter.html diff --git a/docs/Filter/Post.md b/docs/Filter/Post.md deleted file mode 100644 index c976c26b7f976f9b04ddf665da95973c0ddea632..0000000000000000000000000000000000000000 --- a/docs/Filter/Post.md +++ /dev/null @@ -1,69 +0,0 @@ -# Post Filter - -> More info about post filter is in the [official elasticsearch docs][1] - -The post filters are filters that are applied to the search hits at the very end -of a search request, after [aggregations][2] have already been calculated. - -To add post filters use `addPostFilter` method in `Search` object. -`addPostFilter` works like query and filter adders - you can add as many -filters as you want and bool filter will be formed if endpoint has multiple -filters or bool type parameter was provided. - -## Simple example - -```JSON -{ - "post_filter": { - "term": { "color": "red" } - } -} -``` - -And now the query via DSL: - -```php -$termFilter = new TermFilter('color', 'red'); - -$search = new Search(); -$search->addPostFilter($termFilter); -$queryArray = $search->toArray(); -``` - -## Bool example - -```JSON -{ - "post_filter": { - "bool": { - "must": [ - { - "term": { - "color": "red" - } - }, - { - "term": { - "brand": "ana" - } - } - ] - } - } -} -``` - -And now the query via DSL: - -```php -$termFilter1 = new TermFilter('color', 'red'); -$termFilter2 = new TermFilter('brand', 'ana'); - -$search = new Search(); -$search->addPostFilter($termFilter1); -$search->addPostFilter($termFilter2); -$queryArray = $search->toArray(); -``` - -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-post-filter.html -[2]: ../Aggregation/index.md \ No newline at end of file diff --git a/docs/Filter/Prefix.md b/docs/Filter/Prefix.md deleted file mode 100644 index 75e541c43209c3675c7a843d8738e30ad49fa970..0000000000000000000000000000000000000000 --- a/docs/Filter/Prefix.md +++ /dev/null @@ -1,28 +0,0 @@ -# Prefix Filter - -> More info about prefix filter is in the [official elasticsearch docs][1] - -Filters documents that have fields containing terms with a specified prefix. - -## Simple example - -```JSON -{ - "filter" : { - "prefix" : { "user" : "ki" } - } -} -``` - -And now the query via DSL: - -```php -$termFilter = new PrefixFilter('user', 'ki'); - -$search = new Search(); -$search->addFilter($termFilter); - -$queryArray = $search->toArray(); -``` - -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-prefix-filter.html diff --git a/docs/Filter/Query.md b/docs/Filter/Query.md deleted file mode 100644 index 0889b83cfab46c3a67e8671032cfb504d6296327..0000000000000000000000000000000000000000 --- a/docs/Filter/Query.md +++ /dev/null @@ -1,33 +0,0 @@ -# Query Filter - -> More info about query filter is in the [official elasticsearch docs][1] - -Wraps any query to be used as a filter. - -## Simple example - -```JSON -{ - "filter" : { - "query" : { - "query_string" : { - "query" : "this AND that OR thus" - } - } - } -} -``` - -And now the query via DSL: - -```php -$queryStringQuery = new QueryStringQuery('this AND that OR thus'); -$queryFilter = new QueryFilter($queryStringQuery); - -$search = new Search(); -$search->addFilter($queryFilter); - -$queryArray = $search->toArray(); -``` - -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-filter.html diff --git a/docs/Filter/Range.md b/docs/Filter/Range.md deleted file mode 100644 index e2a2315be5beaefe2f0a28c192d3e7727598b4e4..0000000000000000000000000000000000000000 --- a/docs/Filter/Range.md +++ /dev/null @@ -1,33 +0,0 @@ -# Range Filter - -> More info about range filter is in the [official elasticsearch docs][1] - -Filters documents with fields that have terms within a certain range. - -## Simple example - -```JSON -{ - "filter" : { - "range" : { - "age" : { - "gte": 10, - "lte": 20 - } - } - } -} -``` - -And now the query via DSL: - -```php -$rangeFilter = new RangeFilter('age', ['gte' => 10, 'lte' => 20]); - -$search = new Search(); -$search->addFilter($rangeFilter); - -$queryArray = $search->toArray(); -``` - -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-filter.html diff --git a/docs/Filter/Regexp.md b/docs/Filter/Regexp.md deleted file mode 100644 index 99e8c031375a3d2b224857c686d11607799af370..0000000000000000000000000000000000000000 --- a/docs/Filter/Regexp.md +++ /dev/null @@ -1,32 +0,0 @@ -# Regexp Filter - -> More info about regexp filter is in the [official elasticsearch docs][1] - -The regexp filter allows you to use regular expression term queries. -The regexp filter is similar to the [regexp query][2], -except that it is cacheable and can speedup performance in case you are -reusing this filter in your queries. - -## Simple example - -```JSON -{ - "regexp":{ - "name.first": "s.*y" - } -} -``` - -And now the query via DSL: - -```php -$regexpFilter = new RegexpFilter('name.first', 's.*y'); - -$search = new Search(); -$search->addFilter($regexpFilter); - -$queryArray = $search->toArray(); -``` - -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-indices-filter.html -[2]: ../Query/Regexp.md \ No newline at end of file diff --git a/docs/Filter/Script.md b/docs/Filter/Script.md deleted file mode 100644 index 8d35342c7ce1cc92d89eaa76abf30142a2a65db3..0000000000000000000000000000000000000000 --- a/docs/Filter/Script.md +++ /dev/null @@ -1,30 +0,0 @@ -# Script Filter - -> More info about script filter is in the [official elasticsearch docs][1] - -A filter allowing to define scripts as filters - -## Simple example - -```JSON -{ - "filter" : { - "script" : { - "script" : "doc['num1'].value > 1" - } - } -} -``` - -And now the query via DSL: - -```php -$scriptFilter = new ScriptFilter('doc[\'num1\'].value > 1'); - -$search = new Search(); -$search->addFilter($scriptFilter); - -$queryArray = $search->toArray(); -``` - -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-script-filter.html diff --git a/docs/Filter/Term.md b/docs/Filter/Term.md deleted file mode 100644 index 15a482a2ecdc630bea457d060960a5dc4ae2594f..0000000000000000000000000000000000000000 --- a/docs/Filter/Term.md +++ /dev/null @@ -1,28 +0,0 @@ -# Term Filter - -> More info about term filter is in the [official elasticsearch docs][1] - -Filters documents that have fields that contain a term. - -## Simple example - -```JSON -{ - "filter" : { - "term" : { "user" : "kimchy"} - } -} -``` - -And now the query via DSL: - -```php -$termFilter = new TermFilter('user', 'kimchy'); - -$search = new Search(); -$search->addFilter($termFilter); - -$queryArray = $search->toArray(); -``` - -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-filter.html diff --git a/docs/Filter/Terms.md b/docs/Filter/Terms.md deleted file mode 100644 index 6b595ba0c95d6c18fd67c98a066f607234112b50..0000000000000000000000000000000000000000 --- a/docs/Filter/Terms.md +++ /dev/null @@ -1,28 +0,0 @@ -# Terms Filter - -> More info about terms filter is in the [official elasticsearch docs][1] - -Filters documents that have fields that match any of the provided terms. - -## Simple example - -```JSON -{ - "filter" : { - "terms" : { "user" : ["kimchy", "elasticsearch"]} - } -} -``` - -And now the query via DSL: - -```php -$termsFilter = new TermsFilter('user', ['kimchy', 'elasticsearch']); - -$search = new Search(); -$search->addFilter($termsFilter); - -$queryArray = $search->toArray(); -``` - -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-filter.html diff --git a/docs/Filter/Type.md b/docs/Filter/Type.md deleted file mode 100644 index 91915efb8683c90d5e6f7334d54b8c098505976d..0000000000000000000000000000000000000000 --- a/docs/Filter/Type.md +++ /dev/null @@ -1,28 +0,0 @@ -# Type Filter - -> More info about type filter is in the [official elasticsearch docs][1] - -Filters documents matching the provided document / mapping type. - -## Simple example - -```JSON -{ - "type" : { - "value" : "my_type" - } -} -``` - -And now the query via DSL: - -```php -$typeFilter = new TypeFilter('my_type'); - -$search = new Search(); -$search->addFilter($typeFilter); - -$queryArray = $search->toArray(); -``` - -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-type-filter.html diff --git a/docs/Filter/index.md b/docs/Filter/index.md deleted file mode 100644 index d07b941b9774e3d0754b98f7e22fb72305eecd1b..0000000000000000000000000000000000000000 --- a/docs/Filter/index.md +++ /dev/null @@ -1,65 +0,0 @@ -# Filter - -> __WARNING:__ Filters are deprecated since 1.1 and will be removed in 2.0. Elasticsearch from 2.0 casts queries the same way as filters, so there is no reason to have both. More information in [the elasticsearch docs](https://www.elastic.co/guide/en/elasticsearch/reference/2.0/query-dsl-filters.html) - -Objective filter builder represents all available [Elasticsearch filters][1]. - -To form a filtered query you have to create `Search` object. See below an example of match all filter usage. - -```php -$search = new Search(); -$matchAllFilter = new MatchAllFilter(); -$search->addFilter($matchAllFilter); -$queryArray = $search->toArray(); -``` - -Filters handles are necessary little things like where to put `\stdClass` and where to simple array. So by using DSL builder you can be always sure that it will form a correct query. - -Here's `$queryArray` var_dump: - -```php -//$queryArray content -'query' => [ - 'filtered' => [ - 'filter' => [ - 'match_all' => \stdClass(), - ] - ] - ] -``` - -For more information how to combine search queries take a look at [How to search](../HowTo/HowToSearch.md) chapter. - - -## Filters: - - [And](And.md) - - [Bool](Bool.md) - - [Exists](Exists.md) - - [GeoBoundingBox](GeoBoundingBox.md) - - [GeoDistance](GeoDistance.md) - - [GeoDistanceRange](GeoDistanceRange.md) - - [GeoPolygon](GeoPolygon.md) - - [GeoShape](GeoShape.md) - - [GeohashCell](GeohashCell.md) - - [HasChild](HasChild.md) - - [HasParent](HasParent.md) - - [Ids](Ids.md) - - [Indices](Indices.md) - - [Limit](Limit.md) - - [MatchAll](MatchAll.md) - - [Missing](Missing.md) - - [Nested](Nested.md) - - [Not](Not.md) - - [Or](Or.md) - - [Post](Post.md) - - [Prefix](Prefix.md) - - [Query](Query.md) - - [Range](Range.md) - - [Regexp](Regexp.md) - - [Script](Script.md) - - [Term](Term.md) - - [Terms](Terms.md) - - [Type](Type.md) - - -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-filters.html diff --git a/docs/HowTo/HowToSearch.md b/docs/HowTo/HowToSearch.md index 36e32297eff549f7ae41d64eb43388ad0c073b8d..3541c2b89c117da9e7dacc4bab7b34c260f27d38 100644 --- a/docs/HowTo/HowToSearch.md +++ b/docs/HowTo/HowToSearch.md @@ -12,7 +12,7 @@ $search = new Search(); So, when we have a `Search` object we can start add something to it. Usually you will add `Query`, `Filter` and `Aggregation`. -> More info how create [queries](../Query/index.md), [filters](../Filter/index.md) and [aggregations](../Aggregation/index.md) objects. +> More info how create [queries](../Query/index.md) and [aggregations](../Aggregation/index.md) objects. ### Form a Query @@ -43,11 +43,8 @@ At the end it will form this query: ### Form a Filter -> Since Elasticsearch 2.0 all filters were replaced by queries. Queries acts like -> filters when you use them in filter context. For easier future migration use query -> classes instead of filter. (Note, for Elasticsearch 1.* you still should use `ScriptFilter`, -> `HasChildFilter`, `HasParentFilter`, `IndicesFilter`, `NestedFilter`, `PrefixFilter`, -> `RegexpFilter`, `TermFilter` instead of query as they has different structure.) +Since Elasticsearch 2.0 all filters were replaced by queries. Queries acts like +filters when you use them in filter context. To add a filter is the same way like a query. First, lets create some `Filter` object. @@ -66,7 +63,7 @@ Unlike `Query`, when we add a `Filter` with our DSL library it will add a query ```JSON { "query": { - "filtered": { + "bool": { "filter": { "match_all": {} } @@ -120,7 +117,7 @@ The same way it works with a `Filter`. Take a look at this example: ```php $search = new Search(); -$termFilter = new TermFilter('name', 'ongr'); +$termFilter = new TermQuery('name', 'ongr'); $missingFilter = new MissingQuery('disabled'); $existsFilter = new ExistsQuery('tag'); $search->addFilter($termFilter); @@ -133,7 +130,7 @@ Elasticsearch DSL will form this query: ```JSON { "query": { - "filtered": { + "bool": { "filter": { "bool": { "must": [ diff --git a/docs/Query/ConstantScore.md b/docs/Query/ConstantScore.md index dda1c0dad55fbb071c4c262c076f71c28a15c660..733c45017fdf3a292a776ea5d4767b5232c8a7b4 100644 --- a/docs/Query/ConstantScore.md +++ b/docs/Query/ConstantScore.md @@ -20,7 +20,7 @@ Lets take an example to write a constant score query with filter inside. And now the query via DSL: ```php -$termFilter = new TermFilter("user", "kimchy"); +$termFilter = new TermQuery("user", "kimchy"); $constantScoreQuery = new ConstantScoreQuery($termFilter, ["boost" => 1.2]); $search = new Search(); diff --git a/docs/Query/Filtered.md b/docs/Query/Filtered.md deleted file mode 100644 index ab7444ced42260092274820fbfb294d0636f576d..0000000000000000000000000000000000000000 --- a/docs/Query/Filtered.md +++ /dev/null @@ -1,60 +0,0 @@ -# Filtered query - -__DEPRECATED__: filtered query is deprecated and will be removed in ElasticsearchDSL 2.0 - -> More info about filtered query is in the [official elasticsearch docs][1] - -The filtered query is used to combine another query with any filter. Filters are usually faster than queries. - -Lets try to write this example -```JSON -{ - "filtered": { - "query": { - "match": { "tweet": "full text search" } - }, - "filter": { - "range": { "created": { "gte": "now - 1d / d" }} - } - } -} -``` - -In DSL: - -```php -$matchQuery = new MatchQuery('tweet', 'full text search'); -$rangeFilter = new RangeFilter('created', ['gte' => 'now - 1d / d']); - -$filteredQuery = new FilteredQuery($matchQuery, $rangeFilter); - -$search = new Search(); -$search->addQuery($filteredQuery); - -$queryArray = $search->toArray(); -``` - -Or: - -```php -$matchQuery = new MatchQuery('tweet', 'full text search'); -$rangeFilter = new RangeFilter('created', ['gte' => 'now - 1d / d']); - -$filteredQuery = new FilteredQuery(); -$filteredQuery->setQuery($matchQuery); -$filteredQuery->setFilter($rangeFilter); - -$search = new Search(); -$search->addQuery($filteredQuery); - -$queryArray = $search->toArray(); -``` - -Multiple queries and filters can be used with help off [Bool Query][2] and [Bool Filter][3] respectively. - -If query is not set it defaults to Match all, thus Filtered query can be used as filter in places where query is -expected. - -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-filtered-query.html -[2]: Bool.md -[3]: ../Filter/Bool.md diff --git a/docs/Query/FunctionScore.md b/docs/Query/FunctionScore.md index 219ccf963ea4b776ba92133cb594b1d5367c899b..c45cfc00e60086e1b5b2e95a23d2fcea2df31615 100644 --- a/docs/Query/FunctionScore.md +++ b/docs/Query/FunctionScore.md @@ -91,7 +91,7 @@ In DSL: ```php $functionScoreQuery = new FunctionScoreQuery(new MatchAllQuery()); -$rangeFilter = new RangeFilter('price', ['gte' => 10, 'lte' => 100]); +$rangeFilter = new RangeQuery('price', ['gte' => 10, 'lte' => 100]); $functionScoreQuery->addWeightFunction(2, $rangeFilter); $search = new Search(); @@ -104,8 +104,8 @@ $queryArray = $search->toArray(); ```php $functionScoreQuery = new FunctionScoreQuery(new MatchAllQuery()); -$existsFilter = new ExistsFilter('price'); -$functionScoreQuery->addFieldValueFactorFunction('price', 0.5, 'ln', $existsFilter); +$existsQuery = new ExistsQuery('price'); +$functionScoreQuery->addFieldValueFactorFunction('price', 0.5, 'ln', $existsQuery); $search = new Search(); $search->addQuery($functionScoreQuery); diff --git a/docs/Query/index.md b/docs/Query/index.md index 3345e50c9c9397e9bb3297671b3997dda2fc94bb..1540fa038d9536e718e75ad1ca62f602e5abe072 100644 --- a/docs/Query/index.md +++ b/docs/Query/index.md @@ -32,7 +32,6 @@ For more information how to combine search queries take a look at [How to search - [Common terms](CommonTerms.md) - [Constant Score](ConstantScore.md) - [DisMax](DisMax.md) - - [Filtered](Filtered.md) - [Function score](FunctionScore.md) - [Fuzzy](Fuzzy.md) - [Fuzzy like this field](FuzzyLikeThisField.md) diff --git a/docs/index.md b/docs/index.md index 7ff39023cbfa1268202aa6964a3fe12fc8bd4be7..b14009c8734e6144113527c874e157b4f1848bb8 100644 --- a/docs/index.md +++ b/docs/index.md @@ -6,11 +6,8 @@ Everything starts from the `Search` object. We recommend first to take a look at ### Topics: - [Build Queries](Query/index.md) -- [Build Filters](Filter/index.md) - [Build Aggregations](Aggregation/index.md) -> WARNING: Filters are deprecated since 1.1 and will be removed in 2.0. Elasticsearch from 2.0 casts queries the same way as filters, so there is no reason to have both. More information in [the elasticsearch docs](https://www.elastic.co/guide/en/elasticsearch/reference/2.0/query-dsl-filters.html) - ### How to - [How to Search](HowTo/HowToSearch.md) - [How to set custom parameters to Search](HowTo/CustomParameters.md) diff --git a/src/DslTypeAwareTrait.php b/src/DslTypeAwareTrait.php deleted file mode 100644 index 0b3ead2e44653817e472225548baf6d71ef03c40..0000000000000000000000000000000000000000 --- a/src/DslTypeAwareTrait.php +++ /dev/null @@ -1,50 +0,0 @@ -<?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; - -/** - * A trait which handles dsl type. - * - * @deprecated Will be removed in 2.0. - */ -trait DslTypeAwareTrait -{ - /** - * @var string - */ - private $dslType; - - /** - * Returns a dsl type. - * - * @return string - */ - public function getDslType() - { - return $this->dslType; - } - - /** - * Sets a dsl type. - * - * @param string $dslType - * - * @throws \InvalidArgumentException - */ - public function setDslType($dslType) - { - if ($dslType !== 'filter' && $dslType !== 'query') { - throw new \InvalidArgumentException('Not supported dsl type'); - } - $this->dslType = $dslType; - } -} diff --git a/src/Filter/AndFilter.php b/src/Filter/AndFilter.php deleted file mode 100644 index 3be326c2726a8c05b44876583a610d76f402fd39..0000000000000000000000000000000000000000 --- a/src/Filter/AndFilter.php +++ /dev/null @@ -1,105 +0,0 @@ -<?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\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; - -/** - * 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 -{ - use ParametersTrait; - - /** - * @var array - */ - private $filters = []; - - /** - * @param BuilderInterface[] $filters Filter array. - * @param array $parameters Optional parameters. - */ - public function __construct(array $filters = [], array $parameters = []) - { - $this->set($filters); - $this->setParameters($parameters); - } - - /** - * Sets filters. - * - * @param BuilderInterface[] $filters Filter array. - */ - public function set(array $filters) - { - foreach ($filters as $filter) { - $this->add($filter); - } - } - - /** - * Adds filter. - * - * @param BuilderInterface $filter - * - * @return AndFilter - */ - public function add(BuilderInterface $filter) - { - $this->filters[] = [$filter->getType() => $filter->toArray()]; - - return $this; - } - - /** - * Clears filters. - */ - public function clear() - { - $this->filters = []; - } - - /** - * {@inheritdoc} - */ - public function toArray() - { - $query = $this->processArray(); - - if (count($query) > 0) { - $query['filters'] = $this->filters; - } else { - $query = $this->filters; - } - - return $query; - } - - /** - * {@inheritdoc} - */ - public function getType() - { - return 'and'; - } -} diff --git a/src/Filter/BoolFilter.php b/src/Filter/BoolFilter.php deleted file mode 100644 index a3699a0d599f64eb642c0982fc996b99b6841a65..0000000000000000000000000000000000000000 --- a/src/Filter/BoolFilter.php +++ /dev/null @@ -1,30 +0,0 @@ -<?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\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 -{ -} diff --git a/src/Filter/ExistsFilter.php b/src/Filter/ExistsFilter.php deleted file mode 100644 index 31f48949bc8805ccefe77edf8a22ffbdee44cb2c..0000000000000000000000000000000000000000 --- a/src/Filter/ExistsFilter.php +++ /dev/null @@ -1,30 +0,0 @@ -<?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\Filter; - -@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 extends ExistsQuery -{ -} diff --git a/src/Filter/GeoBoundingBoxFilter.php b/src/Filter/GeoBoundingBoxFilter.php deleted file mode 100644 index 1aacf8b4a052958bde60c89ca63b3ddc40b0fdb4..0000000000000000000000000000000000000000 --- a/src/Filter/GeoBoundingBoxFilter.php +++ /dev/null @@ -1,28 +0,0 @@ -<?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\Filter; - -@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 extends GeoBoundingBoxQuery -{ -} diff --git a/src/Filter/GeoDistanceFilter.php b/src/Filter/GeoDistanceFilter.php deleted file mode 100644 index 0de010f27e77f8433f1cdeadb1c47e9c613158ae..0000000000000000000000000000000000000000 --- a/src/Filter/GeoDistanceFilter.php +++ /dev/null @@ -1,28 +0,0 @@ -<?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\Filter; - -@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 extends GeoDistanceQuery -{ -} diff --git a/src/Filter/GeoDistanceRangeFilter.php b/src/Filter/GeoDistanceRangeFilter.php deleted file mode 100644 index 44a24f9a5a25ba12725c102133dd74a0b7a0a20c..0000000000000000000000000000000000000000 --- a/src/Filter/GeoDistanceRangeFilter.php +++ /dev/null @@ -1,28 +0,0 @@ -<?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\Filter; - -@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 extends GeoDistanceRangeQuery -{ -} diff --git a/src/Filter/GeoPolygonFilter.php b/src/Filter/GeoPolygonFilter.php deleted file mode 100644 index 3340aea5d3bca6eac437d88f814d8e9b86637129..0000000000000000000000000000000000000000 --- a/src/Filter/GeoPolygonFilter.php +++ /dev/null @@ -1,28 +0,0 @@ -<?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\Filter; - -@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 extends GeoPolygonQuery -{ -} diff --git a/src/Filter/GeoShapeFilter.php b/src/Filter/GeoShapeFilter.php deleted file mode 100644 index d783268f54393623e96801fb1c10bc93c7396d78..0000000000000000000000000000000000000000 --- a/src/Filter/GeoShapeFilter.php +++ /dev/null @@ -1,28 +0,0 @@ -<?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\Filter; - -@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 extends GeoShapeQuery -{ -} diff --git a/src/Filter/GeohashCellFilter.php b/src/Filter/GeohashCellFilter.php deleted file mode 100644 index 768f02b3022a6f2f8431030a88198a3433455058..0000000000000000000000000000000000000000 --- a/src/Filter/GeohashCellFilter.php +++ /dev/null @@ -1,28 +0,0 @@ -<?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\Filter; - -@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 extends GeohashCellQuery -{ -} diff --git a/src/Filter/HasChildFilter.php b/src/Filter/HasChildFilter.php deleted file mode 100644 index de79c658bb24e316e0d5cc46fe8861324a08ea25..0000000000000000000000000000000000000000 --- a/src/Filter/HasChildFilter.php +++ /dev/null @@ -1,56 +0,0 @@ -<?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\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\Query\HasChildQuery; - -/** - * Elasticsearch has_child filter. - * - * @deprecated Will be removed in 2.0. Use the BoolQuery instead. - */ -class HasChildFilter extends HasChildQuery -{ - use DslTypeAwareTrait; - - /** - * {@inheritdoc} - */ - public function __construct($type, BuilderInterface $query, array $parameters = []) - { - $this->setDslType('filter'); - - parent::__construct($type, $query, $parameters); - } - - /** - * {@inheritdoc} - */ - public function toArray() - { - $result = parent::toArray(); - - if ($this->getDslType() !== 'query') { - $result[$this->getDslType()] = $result['query']; - unset($result['query']); - } - - return $result; - } -} diff --git a/src/Filter/HasParentFilter.php b/src/Filter/HasParentFilter.php deleted file mode 100644 index 90212bcee31f85debd3d538f0fd22965db18265e..0000000000000000000000000000000000000000 --- a/src/Filter/HasParentFilter.php +++ /dev/null @@ -1,56 +0,0 @@ -<?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\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\Query\HasParentQuery; - -/** - * Elasticsearch has_parent filter. - * - * @deprecated Will be removed in 2.0. Use the HasParentQuery instead. - */ -class HasParentFilter extends HasParentQuery -{ - use DslTypeAwareTrait; - - /** - * {@inheritdoc} - */ - public function __construct($type, BuilderInterface $query, array $parameters = []) - { - $this->setDslType('filter'); - - parent::__construct($type, $query, $parameters); - } - - /** - * {@inheritdoc} - */ - public function toArray() - { - $result = parent::toArray(); - - if ($this->getDslType() !== 'query') { - $result[$this->getDslType()] = $result['query']; - unset($result['query']); - } - - return $result; - } -} diff --git a/src/Filter/IdsFilter.php b/src/Filter/IdsFilter.php deleted file mode 100644 index 64a195ebc30e279539153b0b20ea88188028c42e..0000000000000000000000000000000000000000 --- a/src/Filter/IdsFilter.php +++ /dev/null @@ -1,28 +0,0 @@ -<?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\Filter; - -@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 extends IdsQuery -{ -} diff --git a/src/Filter/IndicesFilter.php b/src/Filter/IndicesFilter.php deleted file mode 100644 index a2f829a3770938cfdad5b2f4e564a2816555740f..0000000000000000000000000000000000000000 --- a/src/Filter/IndicesFilter.php +++ /dev/null @@ -1,86 +0,0 @@ -<?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\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 -{ - /** - * @var string[] - */ - private $indices; - - /** - * @var BuilderInterface - */ - private $filter; - - /** - * @var string|BuilderInterface - */ - private $noMatchFilter; - - /** - * @param string[] $indices - * @param BuilderInterface $filter - * @param BuilderInterface $noMatchFilter - */ - public function __construct($indices, $filter, $noMatchFilter = null) - { - $this->indices = $indices; - $this->filter = $filter; - $this->noMatchFilter = $noMatchFilter; - } - - /** - * {@inheritdoc} - */ - public function getType() - { - return 'indices'; - } - - /** - * {@inheritdoc} - */ - public function toArray() - { - if (count($this->indices) > 1) { - $output = ['indices' => $this->indices]; - } else { - $output = ['index' => $this->indices[0]]; - } - - $output['filter'] = [$this->filter->getType() => $this->filter->toArray()]; - - if ($this->noMatchFilter !== null) { - if (is_a($this->noMatchFilter, 'ONGR\ElasticsearchDSL\BuilderInterface')) { - $output['no_match_filter'] = [$this->noMatchFilter->getType() => $this->noMatchFilter->toArray()]; - } else { - $output['no_match_filter'] = $this->noMatchFilter; - } - } - - return $output; - } -} diff --git a/src/Filter/LimitFilter.php b/src/Filter/LimitFilter.php deleted file mode 100644 index b870f8acc171f5be14465d05243340ed56dd7e42..0000000000000000000000000000000000000000 --- a/src/Filter/LimitFilter.php +++ /dev/null @@ -1,30 +0,0 @@ -<?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\Filter; - -@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 extends LimitQuery -{ -} diff --git a/src/Filter/MatchAllFilter.php b/src/Filter/MatchAllFilter.php deleted file mode 100644 index 30c15c27ca542ef1fc2ac33036dabf5fe5f428ae..0000000000000000000000000000000000000000 --- a/src/Filter/MatchAllFilter.php +++ /dev/null @@ -1,30 +0,0 @@ -<?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\Filter; - -@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 extends MatchAllQuery -{ -} diff --git a/src/Filter/MissingFilter.php b/src/Filter/MissingFilter.php deleted file mode 100644 index a1102dd34593de49fe98b2e104a231b6335475cc..0000000000000000000000000000000000000000 --- a/src/Filter/MissingFilter.php +++ /dev/null @@ -1,28 +0,0 @@ -<?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\Filter; - -@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 extends MissingQuery -{ -} diff --git a/src/Filter/NestedFilter.php b/src/Filter/NestedFilter.php deleted file mode 100644 index 120280285316dc84be76bf2b9dc4fa94fc93cea2..0000000000000000000000000000000000000000 --- a/src/Filter/NestedFilter.php +++ /dev/null @@ -1,39 +0,0 @@ -<?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\Filter; - -@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 extends NestedQuery -{ - /** - * {@inheritdoc} - */ - public function toArray() - { - $result = parent::toArray(); - $result['filter'] = $result['query']; - unset($result['query']); - - return $result; - } -} diff --git a/src/Filter/NotFilter.php b/src/Filter/NotFilter.php deleted file mode 100644 index d43653f5c087fc4d00393e2c2a1bc06f2a739e5a..0000000000000000000000000000000000000000 --- a/src/Filter/NotFilter.php +++ /dev/null @@ -1,90 +0,0 @@ -<?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\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; - -/** - * 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 -{ - use ParametersTrait; - - /** - * @var BuilderInterface - */ - private $filter; - - /** - * @param BuilderInterface $filter Filter. - * @param array $parameters Optional parameters. - */ - public function __construct(BuilderInterface $filter = null, array $parameters = []) - { - if ($filter !== null) { - $this->setFilter($filter); - } - $this->setParameters($parameters); - } - - /** - * Returns filter. - * - * @return BuilderInterface - */ - public function getFilter() - { - return $this->filter; - } - - /** - * Sets filter. - * - * @param BuilderInterface $filter - */ - public function setFilter(BuilderInterface $filter) - { - $this->filter = $filter; - } - - /** - * {@inheritdoc} - */ - public function getType() - { - return 'not'; - } - - /** - * {@inheritdoc} - */ - public function toArray() - { - $query = []; - $query['filter'] = [$this->filter->getType() => $this->filter->toArray()]; - - $output = $this->processArray($query); - - return $output; - } -} diff --git a/src/Filter/OrFilter.php b/src/Filter/OrFilter.php deleted file mode 100644 index 834b99e3e1c6e6655dbf1b1ba659f715adbd51a6..0000000000000000000000000000000000000000 --- a/src/Filter/OrFilter.php +++ /dev/null @@ -1,35 +0,0 @@ -<?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\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 -{ - /** - * {@inheritdoc} - */ - public function getType() - { - return 'or'; - } -} diff --git a/src/Filter/PrefixFilter.php b/src/Filter/PrefixFilter.php deleted file mode 100644 index 78d15ec82b6e01064852fd341d7482dc3a093654..0000000000000000000000000000000000000000 --- a/src/Filter/PrefixFilter.php +++ /dev/null @@ -1,41 +0,0 @@ -<?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\Filter; - -@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 extends PrefixQuery -{ - /** - * {@inheritdoc} - */ - public function toArray() - { - $query = [$this->field => $this->value]; - - $output = $this->processArray($query); - - return $output; - } -} diff --git a/src/Filter/QueryFilter.php b/src/Filter/QueryFilter.php deleted file mode 100644 index f9f23cb035783186062d80b44c23766dc52e414c..0000000000000000000000000000000000000000 --- a/src/Filter/QueryFilter.php +++ /dev/null @@ -1,73 +0,0 @@ -<?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\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 -{ - use ParametersTrait; - - /** - * @var BuilderInterface - */ - private $query; - - /** - * @param BuilderInterface $query Query. - * @param array $parameters Optional parameters. - */ - public function __construct($query, array $parameters = []) - { - $this->query = $query; - $this->setParameters($parameters); - } - - /** - * {@inheritdoc} - */ - public function getType() - { - if ($this->hasParameter('_cache')) { - return 'fquery'; - } - - return 'query'; - } - - /** - * {@inheritdoc} - */ - public function toArray() - { - if ($this->hasParameter('_cache')) { - $query = []; - $query['query'] = [$this->query->getType() => $this->query->toArray()]; - $output = $this->processArray($query); - - return $output; - } - - return [$this->query->getType() => $this->query->toArray()]; - } -} diff --git a/src/Filter/RangeFilter.php b/src/Filter/RangeFilter.php deleted file mode 100644 index c891684b20d6a92efff42f21c2a123d1ef53d61a..0000000000000000000000000000000000000000 --- a/src/Filter/RangeFilter.php +++ /dev/null @@ -1,39 +0,0 @@ -<?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\Filter; - -@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 extends RangeQuery -{ - /** - * @param string $field Field name. - * @param array $range Range values. - * @param array $parameters Optional parameters. - */ - public function __construct($field, $range, array $parameters = []) - { - parent::__construct($field, array_merge($range, $parameters)); - } -} diff --git a/src/Filter/RegexpFilter.php b/src/Filter/RegexpFilter.php deleted file mode 100644 index 1bc03ecbd16a2621bda2e1a8d5a937602ad553df..0000000000000000000000000000000000000000 --- a/src/Filter/RegexpFilter.php +++ /dev/null @@ -1,79 +0,0 @@ -<?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\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 -{ - use ParametersTrait; - - /** - * @var string - */ - private $field; - - /** - * @var string - */ - private $regexp; - - /** - * @param string $field Field name. - * @param string $regexp Regular expression. - * @param array $parameters Optional parameters. - */ - public function __construct($field, $regexp, array $parameters = []) - { - $this->field = $field; - $this->regexp = $regexp; - $this->setParameters($parameters); - } - - /** - * {@inheritdoc} - */ - public function getType() - { - return 'regexp'; - } - - /** - * {@inheritdoc} - */ - public function toArray() - { - $query = [ - 'value' => $this->regexp, - ]; - - if ($this->hasParameter('flags')) { - $query['flags'] = $this->getParameter('flags'); - unset($this->parameters['flags']); - } - - $output = $this->processArray([$this->field => $query]); - - return $output; - } -} diff --git a/src/Filter/ScriptFilter.php b/src/Filter/ScriptFilter.php deleted file mode 100644 index 5b751cdfb15348746c6ec40ac45b316a0aace41b..0000000000000000000000000000000000000000 --- a/src/Filter/ScriptFilter.php +++ /dev/null @@ -1,67 +0,0 @@ -<?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\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; - -/** - * 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 -{ - use ParametersTrait; - - /** - * @var string - */ - private $script; - - /** - * @param string $script Script. - * @param array $parameters Optional parameters. - */ - public function __construct($script, array $parameters = []) - { - $this->script = $script; - $this->setParameters($parameters); - } - - /** - * {@inheritdoc} - */ - public function getType() - { - return 'script'; - } - - /** - * {@inheritdoc} - */ - public function toArray() - { - $query = ['script' => $this->script]; - - $output = $this->processArray($query); - - return $output; - } -} diff --git a/src/Filter/TermFilter.php b/src/Filter/TermFilter.php deleted file mode 100644 index fade730812f8828867236696d64d948e09390d62..0000000000000000000000000000000000000000 --- a/src/Filter/TermFilter.php +++ /dev/null @@ -1,60 +0,0 @@ -<?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\Filter; - -@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 extends TermQuery -{ - /** - * @var string - */ - private $field; - - /** - * @var string - */ - private $value; - - /** - * {@inheritdoc} - */ - public function __construct($field, $value, array $parameters = []) - { - $this->field = $field; - $this->value = $value; - - parent::__construct($field, $value, $parameters); - } - - /** - * {@inheritdoc} - */ - public function toArray() - { - $query = [$this->field => $this->value]; - - $output = $this->processArray($query); - - return $output; - } -} diff --git a/src/Filter/TermsFilter.php b/src/Filter/TermsFilter.php deleted file mode 100644 index c42fff8d069e8daa36168b45a94d392fae788d6d..0000000000000000000000000000000000000000 --- a/src/Filter/TermsFilter.php +++ /dev/null @@ -1,28 +0,0 @@ -<?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\Filter; - -@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 extends TermsQuery -{ -} diff --git a/src/Filter/TypeFilter.php b/src/Filter/TypeFilter.php deleted file mode 100644 index 018a59dcd9c5b10c106267e65f32812119079601..0000000000000000000000000000000000000000 --- a/src/Filter/TypeFilter.php +++ /dev/null @@ -1,30 +0,0 @@ -<?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\Filter; - -@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 extends TypeQuery -{ -} diff --git a/src/FilterOrQueryDetectionTrait.php b/src/FilterOrQueryDetectionTrait.php deleted file mode 100644 index 1d3f15ecda645f2d2d94319a51ab8a7edd23385d..0000000000000000000000000000000000000000 --- a/src/FilterOrQueryDetectionTrait.php +++ /dev/null @@ -1,45 +0,0 @@ -<?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; - -/** - * A trait which can detect query or filter is passed. - * - * @deprecated Will be removed in 2.0. - */ -trait FilterOrQueryDetectionTrait -{ - /** - * Detects a dsl type. - * - * @param BuilderInterface $object - * @return string - * - * @throws \InvalidArgumentException - */ - public function detectDslType(BuilderInterface $object) - { - $namespace = get_class($object); - - $dslTypes = ['Filter', 'Query']; - - foreach ($dslTypes as $type) { - $length = strlen($type); - $dslType = substr($namespace, -$length); - if ($dslType === $type) { - return strtolower($dslType); - } - } - - throw new \InvalidArgumentException(); - } -} diff --git a/src/Query/ConstantScoreQuery.php b/src/Query/ConstantScoreQuery.php index d4662d25099fd32be477c22be3637d3be7935637..bb3dc5abf33d0486ee5058860ad4c049fabccd13 100644 --- a/src/Query/ConstantScoreQuery.php +++ b/src/Query/ConstantScoreQuery.php @@ -12,7 +12,6 @@ namespace ONGR\ElasticsearchDSL\Query; use ONGR\ElasticsearchDSL\BuilderInterface; -use ONGR\ElasticsearchDSL\FilterOrQueryDetectionTrait; use ONGR\ElasticsearchDSL\ParametersTrait; /** @@ -21,7 +20,6 @@ use ONGR\ElasticsearchDSL\ParametersTrait; class ConstantScoreQuery implements BuilderInterface { use ParametersTrait; - use FilterOrQueryDetectionTrait; /** * @var BuilderInterface @@ -52,7 +50,7 @@ class ConstantScoreQuery implements BuilderInterface public function toArray() { $query = [ - $this->detectDslType($this->query) => [ + 'filter' => [ $this->query->getType() => $this->query->toArray(), ], ]; diff --git a/src/Query/FilteredQuery.php b/src/Query/FilteredQuery.php deleted file mode 100644 index 0d5504f3b4107737edc22997f24cac6f91b36a36..0000000000000000000000000000000000000000 --- a/src/Query/FilteredQuery.php +++ /dev/null @@ -1,120 +0,0 @@ -<?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 "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 -{ - use ParametersTrait; - - /** - * @var BuilderInterface Used query inside filtered query. - */ - private $query; - - /** - * @var BuilderInterface Used filter inside filtered query. - */ - private $filter; - - /** - * @param BuilderInterface $query - * @param BuilderInterface $filter - */ - public function __construct($query = null, $filter = null) - { - @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 - ); - - if ($query !== null) { - $this->setQuery($query); - } - - if ($filter !== null) { - $this->setFilter($filter); - } - } - - /** - * Sets query. - * - * @param BuilderInterface $query - */ - public function setQuery(BuilderInterface $query) - { - $this->query = $query; - } - - /** - * @return BuilderInterface - */ - public function getQuery() - { - return $this->query; - } - - /** - * Sets filter. - * - * @param BuilderInterface $filter - */ - public function setFilter(BuilderInterface $filter) - { - $this->filter = $filter; - } - - /** - * @return BuilderInterface - */ - public function getFilter() - { - return $this->filter; - } - - /** - * {@inheritdoc} - */ - public function getType() - { - return 'filtered'; - } - - /** - * {@inheritdoc} - */ - public function toArray() - { - $output = []; - - if ($this->getFilter()) { - $output['filter'][$this->getFilter()->getType()] = $this->getFilter()->toArray(); - } - - if ($this->getQuery()) { - $output['query'][$this->getQuery()->getType()] = $this->getQuery()->toArray(); - } - - return count($output) > 0 ? $this->processArray($output) : []; - } -} diff --git a/src/Query/FunctionScoreQuery.php b/src/Query/FunctionScoreQuery.php index 391121f15b583350fe60fc0a3f487a4fe051af31..3f76121c95132d898a01d8f8bab01cad38d013aa 100644 --- a/src/Query/FunctionScoreQuery.php +++ b/src/Query/FunctionScoreQuery.php @@ -12,7 +12,6 @@ namespace ONGR\ElasticsearchDSL\Query; use ONGR\ElasticsearchDSL\BuilderInterface; -use ONGR\ElasticsearchDSL\DslTypeAwareTrait; use ONGR\ElasticsearchDSL\ParametersTrait; /** @@ -21,7 +20,6 @@ use ONGR\ElasticsearchDSL\ParametersTrait; class FunctionScoreQuery implements BuilderInterface { use ParametersTrait; - use DslTypeAwareTrait; /** * Query of filter. @@ -45,7 +43,6 @@ class FunctionScoreQuery implements BuilderInterface { $this->query = $query; $this->setParameters($parameters); - $this->setDslType('query'); } /** @@ -57,16 +54,16 @@ class FunctionScoreQuery implements BuilderInterface } /** - * Modifier to apply filter to the function score function. + * Modifier to apply query to the function score function. * * @param array $function - * @param BuilderInterface $filter + * @param BuilderInterface $query */ - private function applyFilter(array &$function, BuilderInterface $filter = null) + private function applyQuery(array &$function, BuilderInterface $query = null) { - if ($filter) { - $function['filter'] = [ - $filter->getType() => $filter->toArray(), + if ($query) { + $function['query'] = [ + $query->getType() => $query->toArray(), ]; } } @@ -77,11 +74,11 @@ class FunctionScoreQuery implements BuilderInterface * @param string $field * @param float $factor * @param string $modifier - * @param BuilderInterface $filter + * @param BuilderInterface $query * * @return $this */ - public function addFieldValueFactorFunction($field, $factor, $modifier = 'none', BuilderInterface $filter = null) + public function addFieldValueFactorFunction($field, $factor, $modifier = 'none', BuilderInterface $query = null) { $function = [ 'field_value_factor' => [ @@ -91,7 +88,7 @@ class FunctionScoreQuery implements BuilderInterface ], ]; - $this->applyFilter($function, $filter); + $this->applyQuery($function, $query); $this->functions[] = $function; @@ -99,13 +96,13 @@ class FunctionScoreQuery implements BuilderInterface } /** - * Add decay function to function score. Weight and filter are optional. + * Add decay function to function score. Weight and query are optional. * * @param string $type * @param string $field * @param array $function * @param array $options - * @param BuilderInterface $filter + * @param BuilderInterface $query * * @return $this */ @@ -114,7 +111,7 @@ class FunctionScoreQuery implements BuilderInterface $field, array $function, array $options = [], - BuilderInterface $filter = null + BuilderInterface $query = null ) { $function = [ $type => array_merge( @@ -123,7 +120,7 @@ class FunctionScoreQuery implements BuilderInterface ), ]; - $this->applyFilter($function, $filter); + $this->applyQuery($function, $query); $this->functions[] = $function; @@ -131,20 +128,20 @@ class FunctionScoreQuery implements BuilderInterface } /** - * Adds function to function score without decay function. Influence search score only for specific filter. + * Adds function to function score without decay function. Influence search score only for specific query. * * @param float $weight - * @param BuilderInterface $filter + * @param BuilderInterface $query * * @return $this */ - public function addWeightFunction($weight, BuilderInterface $filter = null) + public function addWeightFunction($weight, BuilderInterface $query = null) { $function = [ 'weight' => $weight, ]; - $this->applyFilter($function, $filter); + $this->applyQuery($function, $query); $this->functions[] = $function; @@ -155,17 +152,17 @@ class FunctionScoreQuery implements BuilderInterface * Adds random score function. Seed is optional. * * @param mixed $seed - * @param BuilderInterface $filter + * @param BuilderInterface $query * * @return $this */ - public function addRandomFunction($seed = null, BuilderInterface $filter = null) + public function addRandomFunction($seed = null, BuilderInterface $query = null) { $function = [ 'random_score' => $seed ? [ 'seed' => $seed ] : new \stdClass(), ]; - $this->applyFilter($function, $filter); + $this->applyQuery($function, $query); $this->functions[] = $function; @@ -178,7 +175,7 @@ class FunctionScoreQuery implements BuilderInterface * @param string $script * @param array $params * @param array $options - * @param BuilderInterface $filter + * @param BuilderInterface $query * * @return $this */ @@ -186,7 +183,7 @@ class FunctionScoreQuery implements BuilderInterface $script, array $params = [], array $options = [], - BuilderInterface $filter = null + BuilderInterface $query = null ) { $function = [ 'script_score' => array_merge( @@ -198,7 +195,7 @@ class FunctionScoreQuery implements BuilderInterface ), ]; - $this->applyFilter($function, $filter); + $this->applyQuery($function, $query); $this->functions[] = $function; @@ -225,7 +222,7 @@ class FunctionScoreQuery implements BuilderInterface public function toArray() { $query = [ - strtolower($this->getDslType()) => [ + 'query' => [ $this->query->getType() => $this->query->toArray(), ], 'functions' => $this->functions, diff --git a/src/SearchEndpoint/FilterEndpoint.php b/src/SearchEndpoint/FilterEndpoint.php index e9c3d8f57e5f03133a22dafb5554a5b2028dc0da..bc2a0d4cb32ba6ac5e33303216ed5ef4d603e7d1 100644 --- a/src/SearchEndpoint/FilterEndpoint.php +++ b/src/SearchEndpoint/FilterEndpoint.php @@ -11,7 +11,6 @@ namespace ONGR\ElasticsearchDSL\SearchEndpoint; -use ONGR\ElasticsearchDSL\Query\FilteredQuery; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** @@ -33,10 +32,7 @@ class FilterEndpoint extends QueryEndpoint return null; } - $query = new FilteredQuery(); - $query->setFilter($this->getBool()); - - $this->addReference('filtered_query', $query); + $this->addReference('filter_query', $this->getBool()); } /** diff --git a/src/SearchEndpoint/QueryEndpoint.php b/src/SearchEndpoint/QueryEndpoint.php index 9f14df543c3a4c0f3f463501901c97987a65b40c..e7f040cbb73003ec686e00a94be2503ea59298c9 100644 --- a/src/SearchEndpoint/QueryEndpoint.php +++ b/src/SearchEndpoint/QueryEndpoint.php @@ -13,7 +13,6 @@ namespace ONGR\ElasticsearchDSL\SearchEndpoint; use ONGR\ElasticsearchDSL\BuilderInterface; use ONGR\ElasticsearchDSL\Query\BoolQuery; -use ONGR\ElasticsearchDSL\Query\FilteredQuery; use ONGR\ElasticsearchDSL\Serializer\Normalizer\OrderedNormalizerInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; @@ -32,29 +31,28 @@ class QueryEndpoint extends AbstractSearchEndpoint implements OrderedNormalizerI */ private $bool; + /** + * @var bool + */ + private $filtersSet = false; + /** * {@inheritdoc} */ public function normalize(NormalizerInterface $normalizer, $format = null, array $context = []) { - $query = $this->getBool(); - - if ($this->hasReference('filtered_query')) { - /** @var FilteredQuery $filteredQuery */ - $filteredQuery = $this->getReference('filtered_query'); - - if ($query) { - $filteredQuery->setQuery($query); - } - - $query = $filteredQuery; + if (!$this->filtersSet && $this->hasReference('filter_query')) { + /** @var BuilderInterface $filter */ + $filter = $this->getReference('filter_query'); + $this->addToBool($filter, BoolQuery::FILTER); + $this->filtersSet = true; } - if (!$query) { + if (!$this->bool) { return null; } - return [$query->getType() => $query->toArray()]; + return [$this->bool->getType() => $this->bool->toArray()]; } /** @@ -71,7 +69,7 @@ class QueryEndpoint extends AbstractSearchEndpoint implements OrderedNormalizerI public function addToBool(BuilderInterface $builder, $boolType = null, $key = null) { if (!$this->bool) { - $this->bool = $this->getBoolInstance(); + $this->bool = new BoolQuery(); } return $this->bool->add($builder, $boolType, $key); @@ -93,16 +91,6 @@ class QueryEndpoint extends AbstractSearchEndpoint implements OrderedNormalizerI return $this->bool; } - /** - * Returns new bool instance for the endpoint. - * - * @return BoolQuery - */ - protected function getBoolInstance() - { - return new BoolQuery(); - } - /** * {@inheritdoc} */ diff --git a/tests/Aggregation/FilterAggregationTest.php b/tests/Aggregation/FilterAggregationTest.php index 94167801e076779843a4ef32f405026a8b892612..6f8fe99f6409a6cc61c2ba294ef2d3b738a766a1 100644 --- a/tests/Aggregation/FilterAggregationTest.php +++ b/tests/Aggregation/FilterAggregationTest.php @@ -13,10 +13,10 @@ namespace ONGR\ElasticsearchDSL\Tests\Aggregation; use ONGR\ElasticsearchDSL\Aggregation\FilterAggregation; use ONGR\ElasticsearchDSL\Aggregation\HistogramAggregation; -use ONGR\ElasticsearchDSL\Filter\TermFilter; use ONGR\ElasticsearchDSL\Query\BoolQuery; use ONGR\ElasticsearchDSL\Query\MatchAllQuery; use ONGR\ElasticsearchDSL\Query\MissingQuery; +use ONGR\ElasticsearchDSL\Query\TermQuery; class FilterAggregationTest extends \PHPUnit_Framework_TestCase { @@ -70,7 +70,7 @@ class FilterAggregationTest extends \PHPUnit_Framework_TestCase // Case #2 testing bool filter. $aggregation = new FilterAggregation('test_agg'); $matchAllFilter = new MatchAllQuery(); - $termFilter = new TermFilter('acme', 'foo'); + $termFilter = new TermQuery('acme', 'foo'); $boolFilter = new BoolQuery(); $boolFilter->add($matchAllFilter); $boolFilter->add($termFilter); diff --git a/tests/DslTypeAwareTraitTest.php b/tests/DslTypeAwareTraitTest.php deleted file mode 100644 index 2b87d14f45f759ed4382fbb29ec36dd69e7220eb..0000000000000000000000000000000000000000 --- a/tests/DslTypeAwareTraitTest.php +++ /dev/null @@ -1,61 +0,0 @@ -<?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\Tests\Unit\DSL; - -use ONGR\ElasticsearchDSL\DslTypeAwareTrait; - -/** - * Test for DslTypeAwareTrait. - */ -class DslTypeAwareTraitTest extends \PHPUnit_Framework_TestCase -{ - /** - * @var DslTypeAwareTrait - */ - private $mock; - - /** - * {@inheritdoc} - */ - public function setUp() - { - $this->mock = $this->getMockForTrait('ONGR\ElasticsearchDSL\DslTypeAwareTrait'); - } - - /** - * Tests if setDslType throws exception. - * - * @expectedException \InvalidArgumentException - */ - public function testIfSetDslTypeExceptionThrowsException() - { - $this->mock->setDslType('foo'); - } - - /** - * Tests if setDslType sets filter. - */ - public function testIfSetDslTypeSetsFilter() - { - $this->mock->setDslType('filter'); - $this->assertEquals('filter', $this->mock->getDslType()); - } - - /** - * Tests if setDslType sets query. - */ - public function testIfSetDslTypeSetsQuery() - { - $this->mock->setDslType('query'); - $this->assertEquals('query', $this->mock->getDslType()); - } -} diff --git a/tests/Filter/AndFilterTest.php b/tests/Filter/AndFilterTest.php deleted file mode 100644 index e768a506672c50b70b566f9d83650caca7b22dff..0000000000000000000000000000000000000000 --- a/tests/Filter/AndFilterTest.php +++ /dev/null @@ -1,131 +0,0 @@ -<?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\Tests\Filter; - -use ONGR\ElasticsearchDSL\Filter\AndFilter; - -class AndFilterTest extends \PHPUnit_Framework_TestCase -{ - /** - * Tests GetType method. - */ - public function testGetType() - { - $filter = new AndFilter([], []); - $result = $filter->getType(); - $this->assertEquals('and', $result); - } - - /** - * Data provider for testToArray function. - * - * @return array - */ - public function getArrayDataProvider() - { - $mockBuildeFfirstFilter = $this->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface') - ->getMock(); - $mockBuildeFfirstFilter->expects($this->any()) - ->method('getType') - ->willReturn('term'); - $mockBuildeFfirstFilter->expects($this->any()) - ->method('toArray') - ->willReturn(['test_field' => ['test_value' => 'test']]); - - $mockBuilderSecondFilter = $this->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface') - ->getMock(); - $mockBuilderSecondFilter->expects($this->any()) - ->method('getType') - ->willReturn('prefix'); - $mockBuilderSecondFilter->expects($this->any()) - ->method('toArray') - ->willReturn(['test_field' => ['test_value' => 'test']]); - - return [ - // Case #1. - [ - [$mockBuildeFfirstFilter], - [], - [ - [ - 'term' => [ - 'test_field' => [ - 'test_value' => 'test', - ], - ], - ], - ], - ], - // Case #2. - [ - [$mockBuildeFfirstFilter, $mockBuilderSecondFilter], - [], - [ - [ - 'term' => [ - 'test_field' => [ - 'test_value' => 'test', - ], - ], - ], - [ - 'prefix' => [ - 'test_field' => [ - 'test_value' => 'test', - ], - ], - ], - ], - ], - // Case #3. - [ - [$mockBuildeFfirstFilter, $mockBuilderSecondFilter], - ['type' => 'acme'], - [ - 'filters' => [ - 0 => [ - 'term' => [ - 'test_field' => [ - 'test_value' => 'test', - ], - ], - ], - 1 => [ - 'prefix' => [ - 'test_field' => [ - 'test_value' => 'test', - ], - ], - ], - ], - 'type' => 'acme', - ], - ], - ]; - } - - /** - * Test for filter toArray() method. - * - * @param BuilderInterface[] $filters Array. - * @param array $parameters Optional parameters. - * @param array $expected Expected values. - * - * @dataProvider getArrayDataProvider - */ - public function testToArray($filters, $parameters, $expected) - { - $filter = new AndFilter($filters, $parameters); - $result = $filter->toArray(); - $this->assertEquals($expected, $result); - } -} diff --git a/tests/Filter/ExistsFilterTest.php b/tests/Filter/ExistsFilterTest.php deleted file mode 100644 index fa46ac6ca4bcdf2d6b92751c79c5fe208b1cf683..0000000000000000000000000000000000000000 --- a/tests/Filter/ExistsFilterTest.php +++ /dev/null @@ -1,38 +0,0 @@ -<?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\Tests\Filter; - -use ONGR\ElasticsearchDSL\Filter\ExistsFilter; - -/** - * Unit test for ExistsFilter. - */ -class ExistsFilterTest extends \PHPUnit_Framework_TestCase -{ - /** - * Tests ExistsFilter#getType() method. - */ - public function testGetType() - { - $filter = new ExistsFilter('bar'); - $this->assertEquals('exists', $filter->getType()); - } - - /** - * Tests ExistsFilter#toArray() method. - */ - public function testToArray() - { - $filter = new ExistsFilter('bar'); - $this->assertEquals(['field' => 'bar'], $filter->toArray()); - } -} diff --git a/tests/Filter/GeoBoundingBoxFilterTest.php b/tests/Filter/GeoBoundingBoxFilterTest.php deleted file mode 100644 index 69abbc94e1ac4beb95e5d53e8e528c1f21101c96..0000000000000000000000000000000000000000 --- a/tests/Filter/GeoBoundingBoxFilterTest.php +++ /dev/null @@ -1,97 +0,0 @@ -<?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\Tests\Filter; - -use ONGR\ElasticsearchDSL\Filter\GeoBoundingBoxFilter; - -class GeoBoundingBoxFilterTest extends \PHPUnit_Framework_TestCase -{ - /** - * Tests getType method. - */ - public function testGetType() - { - $filter = new GeoBoundingBoxFilter('location', []); - $result = $filter->getType(); - $this->assertEquals('geo_bounding_box', $result); - } - - /** - * Test if exception is thrown when geo points are not set. - * - * @expectedException \LogicException - */ - public function testGeoBoundBoxFilterException() - { - $filter = new GeoBoundingBoxFilter('location', []); - $filter->toArray(); - } - - /** - * Data provider to testToArray. - * - * @return array - */ - public function getArrayDataProvider() - { - return [ - // Case #1 (2 values). - [ - 'location', - [ - ['lat' => 40.73, 'lon' => -74.1], - ['lat' => 40.01, 'lon' => -71.12], - ], - ['parameter' => 'value'], - [ - 'location' => [ - 'top_left' => ['lat' => 40.73, 'lon' => -74.1], - 'bottom_right' => ['lat' => 40.01, 'lon' => -71.12], - ], - 'parameter' => 'value', - ], - ], - // Case #2 (4 values). - [ - 'location', - [40.73, -74.1, 40.01, -71.12], - ['parameter' => 'value'], - [ - 'location' => [ - 'top' => 40.73, - 'left' => -74.1, - 'bottom' => 40.01, - 'right' => -71.12, - ], - 'parameter' => 'value', - ], - ], - ]; - } - - /** - * Tests toArray method. - * - * @param string $field Field name. - * @param array $values Bounding box values. - * @param array $parameters Optional parameters. - * @param array $expected Expected result. - * - * @dataProvider getArrayDataProvider - */ - public function testToArray($field, $values, $parameters, $expected) - { - $filter = new GeoBoundingBoxFilter($field, $values, $parameters); - $result = $filter->toArray(); - $this->assertEquals($expected, $result); - } -} diff --git a/tests/Filter/GeoDistanceFilterTest.php b/tests/Filter/GeoDistanceFilterTest.php deleted file mode 100644 index f76eb3b92d73bc2cc161311f39c1637372d28e17..0000000000000000000000000000000000000000 --- a/tests/Filter/GeoDistanceFilterTest.php +++ /dev/null @@ -1,72 +0,0 @@ -<?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\Tests\Filter; - -use ONGR\ElasticsearchDSL\Filter\GeoDistanceFilter; - -class GeoDistanceFilterTest extends \PHPUnit_Framework_TestCase -{ - /** - * Tests GetType method. - */ - public function testGetType() - { - $filter = new GeoDistanceFilter('test_field', 'test_distance', 'test_location'); - $result = $filter->getType(); - $this->assertEquals('geo_distance', $result); - } - - /** - * Data provider to testToArray. - * - * @return array - */ - public function getArrayDataProvider() - { - return [ - // Case #1. - [ - 'location', - '200km', - ['lat' => 40, 'lon' => -70], - [], - ['distance' => '200km', 'location' => ['lat' => 40, 'lon' => -70]], - ], - // Case #2. - [ - 'location', - '20km', - ['lat' => 0, 'lon' => 0], - ['parameter' => 'value'], - ['distance' => '20km', 'location' => ['lat' => 0, 'lon' => 0], 'parameter' => 'value'], - ], - ]; - } - - /** - * Tests toArray method. - * - * @param string $field Field name. - * @param string $distance Distance. - * @param array $location Location. - * @param array $parameters Optional parameters. - * @param array $expected Expected result. - * - * @dataProvider getArrayDataProvider - */ - public function testToArray($field, $distance, $location, $parameters, $expected) - { - $filter = new GeoDistanceFilter($field, $distance, $location, $parameters); - $result = $filter->toArray(); - $this->assertEquals($expected, $result); - } -} diff --git a/tests/Filter/GeoDistanceRangeFilterTest.php b/tests/Filter/GeoDistanceRangeFilterTest.php deleted file mode 100644 index 69087113b8ffdc686375d3e0f688b3139fc8909a..0000000000000000000000000000000000000000 --- a/tests/Filter/GeoDistanceRangeFilterTest.php +++ /dev/null @@ -1,72 +0,0 @@ -<?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\Tests\Filter; - -use ONGR\ElasticsearchDSL\Filter\GeoDistanceRangeFilter; - -class GeoDistanceRangeFilterTest extends \PHPUnit_Framework_TestCase -{ - /** - * Tests GetType method. - */ - public function testGetType() - { - $filter = new GeoDistanceRangeFilter('test_field', 'test_distance', 'test_location'); - $result = $filter->getType(); - $this->assertEquals('geo_distance_range', $result); - } - - /** - * Data provider to testToArray. - * - * @return array - */ - public function getArrayDataProvider() - { - return [ - // Case #1. - [ - 'location', - ['from' => '200km', 'to' => '400km'], - ['lat' => 40, 'lon' => -70], - [], - ['from' => '200km', 'to' => '400km', 'location' => ['lat' => 40, 'lon' => -70]], - ], - // Case #2. - [ - 'location', - ['from' => '150km', 'to' => '180km'], - ['lat' => 0, 'lon' => 0], - ['parameter' => 'value'], - ['from' => '150km', 'to' => '180km', 'location' => ['lat' => 0, 'lon' => 0], 'parameter' => 'value'], - ], - ]; - } - - /** - * Tests toArray method. - * - * @param string $field Field name. - * @param array $range Distance range. - * @param array $location Location. - * @param array $parameters Optional parameters. - * @param array $expected Expected result. - * - * @dataProvider getArrayDataProvider - */ - public function testToArray($field, $range, $location, $parameters, $expected) - { - $filter = new GeoDistanceRangeFilter($field, $range, $location, $parameters); - $result = $filter->toArray(); - $this->assertEquals($expected, $result); - } -} diff --git a/tests/Filter/GeoPolygonFilterTest.php b/tests/Filter/GeoPolygonFilterTest.php deleted file mode 100644 index 97c3c7eda7c5efbb94b5d4c5fe6853bac848e6f0..0000000000000000000000000000000000000000 --- a/tests/Filter/GeoPolygonFilterTest.php +++ /dev/null @@ -1,98 +0,0 @@ -<?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\Tests\Filter; - -use ONGR\ElasticsearchDSL\Filter\GeoPolygonFilter; - -class GeoPolygonFilterTest extends \PHPUnit_Framework_TestCase -{ - /** - * Tests GetType method. - */ - public function testGetType() - { - $filter = new GeoPolygonFilter('test_field'); - $result = $filter->getType(); - $this->assertEquals('geo_polygon', $result); - } - - /** - * Data provider to testToArray. - * - * @return array - */ - public function getArrayDataProvider() - { - return [ - // Case #1. - [ - 'location', - [ - ['lat' => 20, 'lon' => -80], - ['lat' => 30, 'lon' => -40], - ['lat' => 70, 'lon' => -90], - ], - [], - [ - 'location' => [ - 'points' => [ - ['lat' => 20, 'lon' => -80], - ['lat' => 30, 'lon' => -40], - ['lat' => 70, 'lon' => -90], - ], - ], - ], - ], - // Case #2. - [ - 'location', - [], - ['parameter' => 'value'], - [ - 'location' => ['points' => []], - 'parameter' => 'value', - ], - ], - // Case #3. - [ - 'location', - [ - ['lat' => 20, 'lon' => -80], - ], - ['parameter' => 'value'], - [ - 'location' => [ - 'points' => [['lat' => 20, 'lon' => -80]], - ], - 'parameter' => 'value', - ], - ], - ]; - } - - /** - * Tests toArray method. - * - * @param string $field Field name. - * @param array $points Polygon's points. - * @param array $parameters Optional parameters. - * @param array $expected Expected result. - * - * @dataProvider getArrayDataProvider - */ - public function testToArray($field, $points, $parameters, $expected) - { - $filter = new GeoPolygonFilter($field, $points, $parameters); - $result = $filter->toArray(); - $this->assertEquals($expected, $result); - } -} diff --git a/tests/Filter/HasChildFilterTest.php b/tests/Filter/HasChildFilterTest.php deleted file mode 100644 index 0be852a44e1d0338285110297c0811f4e478fbee..0000000000000000000000000000000000000000 --- a/tests/Filter/HasChildFilterTest.php +++ /dev/null @@ -1,85 +0,0 @@ -<?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\Tests\Filter; - -use ONGR\ElasticsearchDSL\Filter\HasChildFilter; - -class HasChildFilterTest extends \PHPUnit_Framework_TestCase -{ - /** - * Tests GetType method. - */ - public function testGetType() - { - $mock = $this->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface')->getMock(); - $filter = new HasChildFilter('test_field', $mock); - $result = $filter->getType(); - $this->assertEquals('has_child', $result); - } - - /** - * Data provider to testToArray. - * - * @return array - */ - public function getArrayDataProvider() - { - return [ - // Case #1. - [ - 'comment', - 'term', - ['name' => 'foo'], - [], - 'filter', - ['type' => 'comment', 'filter' => ['term' => ['name' => 'foo']]], - ], - // Case #2. - [ - 'comment', - 'term', - ['name' => 'foo'], - ['parameter' => 'value'], - 'query', - ['type' => 'comment', 'query' => ['term' => ['name' => 'foo']], 'parameter' => 'value'], - ], - ]; - } - - /** - * Tests toArray method. - * - * @param string $type Child type. - * @param string $queryType Type of query for mock query class. - * @param array $queryToArray Return value for mock query class toArray method. - * @param array $parameters Optional parameters. - * @param string $dslType Filter or query. - * @param array $expected Expected result. - * - * @dataProvider getArrayDataProvider - */ - public function testToArray($type, $queryType, $queryToArray, $parameters, $dslType, $expected) - { - $mockQuery = $this->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface')->getMock(); - $mockQuery->expects($this->once()) - ->method('getType') - ->will($this->returnValue($queryType)); - $mockQuery->expects($this->once()) - ->method('toArray') - ->will($this->returnValue($queryToArray)); - - $filter = new HasChildFilter($type, $mockQuery, $parameters); - $filter->setDslType($dslType); - $result = $filter->toArray(); - $this->assertEquals($expected, $result); - } -} diff --git a/tests/Filter/HasParentFilterTest.php b/tests/Filter/HasParentFilterTest.php deleted file mode 100644 index d0ad8a56b8730effbc30762645b8bbbb1fa594b6..0000000000000000000000000000000000000000 --- a/tests/Filter/HasParentFilterTest.php +++ /dev/null @@ -1,85 +0,0 @@ -<?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\Tests\Filter; - -use ONGR\ElasticsearchDSL\Filter\HasParentFilter; - -class HasParentFilterTest extends \PHPUnit_Framework_TestCase -{ - /** - * Tests GetType method. - */ - public function testGetType() - { - $mock = $this->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface')->getMock(); - $filter = new HasParentFilter('test_field', $mock); - $result = $filter->getType(); - $this->assertEquals('has_parent', $result); - } - - /** - * Data provider to testToArray. - * - * @return array - */ - public function getArrayDataProvider() - { - return [ - // Case #1. - [ - 'content', - 'term', - ['title' => 'nested'], - [], - 'filter', - ['parent_type' => 'content', 'filter' => ['term' => ['title' => 'nested']]], - ], - // Case #2. - [ - 'content', - 'term', - ['title' => 'nested'], - ['parameter' => 'value'], - 'query', - ['parent_type' => 'content', 'query' => ['term' => ['title' => 'nested']], 'parameter' => 'value'], - ], - ]; - } - - /** - * Tests toArray method. - * - * @param string $parentType Parent type. - * @param string $queryType Type of query for mock query class. - * @param array $queryToArray Return value for mock query class toArray method. - * @param array $parameters Optional parameters. - * @param string $dslType Filter or query. - * @param array $expected Expected result. - * - * @dataProvider getArrayDataProvider - */ - public function testToArray($parentType, $queryType, $queryToArray, $parameters, $dslType, $expected) - { - $mockQuery = $this->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface')->getMock(); - $mockQuery->expects($this->once()) - ->method('getType') - ->will($this->returnValue($queryType)); - $mockQuery->expects($this->once()) - ->method('toArray') - ->will($this->returnValue($queryToArray)); - - $filter = new HasParentFilter($parentType, $mockQuery, $parameters); - $filter->setDslType($dslType); - $result = $filter->toArray(); - $this->assertEquals($expected, $result); - } -} diff --git a/tests/Filter/IdsFilterTest.php b/tests/Filter/IdsFilterTest.php deleted file mode 100644 index 84ff9e9dd4c4cbcf790abc0dcbe920283cc2063e..0000000000000000000000000000000000000000 --- a/tests/Filter/IdsFilterTest.php +++ /dev/null @@ -1,60 +0,0 @@ -<?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\Tests\Filter; - -use ONGR\ElasticsearchDSL\Filter\IdsFilter; - -class IdsFilterTest extends \PHPUnit_Framework_TestCase -{ - /** - * Tests GetType method. - */ - public function testGetType() - { - $filter = new IdsFilter([], []); - $result = $filter->getType(); - $this->assertEquals('ids', $result); - } - - /** - * Data provider to testGetToArray. - * - * @return array - */ - public function getArrayDataProvider() - { - return [ - // Case #1. - [['acme', 'bar'], ['type' => 'acme'], ['values' => ['acme', 'bar'], 'type' => 'acme']], - // Case #2. - [[], [], ['values' => []]], - // Case #3. - [['acme'], [], ['values' => ['acme']]], - ]; - } - - /** - * Test for filter toArray() method. - * - * @param string[] $values Ids' values. - * @param array $parameters Optional parameters. - * @param array $expected Expected result. - * - * @dataProvider getArrayDataProvider - */ - public function testToArray($values, $parameters, $expected) - { - $filter = new IdsFilter($values, $parameters); - $result = $filter->toArray(); - $this->assertEquals($expected, $result); - } -} diff --git a/tests/Filter/IndicesFilterTest.php b/tests/Filter/IndicesFilterTest.php deleted file mode 100644 index d6c602718348d6bedd4689b9bc58a742c30eff95..0000000000000000000000000000000000000000 --- a/tests/Filter/IndicesFilterTest.php +++ /dev/null @@ -1,108 +0,0 @@ -<?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\Tests\Filter; - -use ONGR\ElasticsearchDSL\Filter\IndicesFilter; - -class IndicesFilterTest extends \PHPUnit_Framework_TestCase -{ - /** - * Tests GetType method. - */ - public function testGetType() - { - $filter = new IndicesFilter([], '', null); - $this->assertEquals('indices', $filter->getType()); - } - - /** - * Tests if Indices qty is greater than one. - */ - public function testToArrayIfIndicesQtyIsGreaterThanOne() - { - $mockBuilder = $this->indicesQtyMockBuilder(['test_field' => ['test_value' => 'test']]); - - $filter = new IndicesFilter(['foo', 'bar'], $mockBuilder, null); - $expectedResult = [ - 'indices' => [0 => 'foo', 1 => 'bar'], - 'filter' => ['term' => ['test_field' => ['test_value' => 'test']]], - ]; - $result = $filter->toArray(); - $this->assertEquals($expectedResult, $result); - } - - /** - * Test if Indices qty is less than one. - */ - public function testToArrayIfIndicesQtyIsLessThanOne() - { - $mockBuilder = $this->indicesQtyMockBuilder(['test_field' => ['test_value' => 'test']]); - $filter = new IndicesFilter(['foo'], $mockBuilder, null); - $expectedResult = ['index' => 'foo', 'filter' => ['term' => ['test_field' => ['test_value' => 'test']]]]; - $result = $filter->toArray(); - $this->assertEquals($expectedResult, $result); - } - - /** - * Test. - */ - public function testWhenNoMatchFilterIsNotNull() - { - $mockBuilder = $this->indicesQtyMockBuilder(['tag' => 'wow']); - $noMatchFilterMockBuilder = $this->indicesQtyMockBuilder(['tag' => 'kow']); - $filter = new IndicesFilter(['foo'], $mockBuilder, $noMatchFilterMockBuilder); - $expectedResult = [ - 'index' => 'foo', - 'filter' => ['term' => ['tag' => 'wow']], - 'no_match_filter' => ['term' => ['tag' => 'kow']], - ]; - $result = $filter->toArray(); - $this->assertEquals($expectedResult, $result); - } - - /** - * Test. - */ - public function testWhenNoMatchFilterIsEmpty() - { - $mockBuilder = $this->indicesQtyMockBuilder(['tag' => 'wow']); - $filter = new IndicesFilter(['foo'], $mockBuilder, ''); - $expectedResult = [ - 'index' => 'foo', - 'filter' => ['term' => ['tag' => 'wow']], - 'no_match_filter' => '', - ]; - $result = $filter->toArray(); - $this->assertEquals($expectedResult, $result); - } - - /** - * Mock Builder. - * - * @param array $param Expected values. - * - * @return \PHPUnit_Framework_MockObject_MockObject - */ - private function indicesQtyMockBuilder(array $param = []) - { - $mockBuilder = $this->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface') - ->getMock(); - $mockBuilder->expects($this->any()) - ->method('getType') - ->willReturn('term'); - $mockBuilder->expects($this->any()) - ->method('toArray') - ->willReturn($param); - - return $mockBuilder; - } -} diff --git a/tests/Filter/LimitFilterTest.php b/tests/Filter/LimitFilterTest.php deleted file mode 100644 index 41b963f2620c706f0e1b3b89981d9fd8c9785d3c..0000000000000000000000000000000000000000 --- a/tests/Filter/LimitFilterTest.php +++ /dev/null @@ -1,36 +0,0 @@ -<?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\Tests\Filter; - -use ONGR\ElasticsearchDSL\Filter\LimitFilter; - -class LimitFilterTest extends \PHPUnit_Framework_TestCase -{ - /** - * Tests GetType method. - */ - public function testGetType() - { - $filter = new LimitFilter(0); - $this->assertEquals('limit', $filter->getType()); - } - - /** - * Test for filter toArray() method. - */ - public function testToArray() - { - $filter = new LimitFilter(0); - $expectedResult = ['value' => 0]; - $this->assertEquals($expectedResult, $filter->toArray()); - } -} diff --git a/tests/Filter/MatchAllFilterTest.php b/tests/Filter/MatchAllFilterTest.php deleted file mode 100644 index eb2b2f6f14e85fb16c4af2a1df0a4f2ca16ff067..0000000000000000000000000000000000000000 --- a/tests/Filter/MatchAllFilterTest.php +++ /dev/null @@ -1,38 +0,0 @@ -<?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\Tests\Filter; - -use ONGR\ElasticsearchDSL\Filter\MatchAllFilter; - -class MatchAllFilterTest extends \PHPUnit_Framework_TestCase -{ - /** - * Tests GetType method, it should return 'match_all'. - */ - public function testGetType() - { - $filter = new MatchAllFilter(); - $result = $filter->getType(); - $this->assertEquals('match_all', $result); - } - - /** - * Test toArray method. - */ - public function testToArrayItShouldReturnStdClass() - { - $filter = new MatchAllFilter(); - $result = $filter->toArray(); - $expectedResult = []; - $this->assertEquals($expectedResult, $result); - } -} diff --git a/tests/Filter/MissingFilterTest.php b/tests/Filter/MissingFilterTest.php deleted file mode 100644 index 7ebab6b0ea588e0247c1519d17e1b9c0446e8e52..0000000000000000000000000000000000000000 --- a/tests/Filter/MissingFilterTest.php +++ /dev/null @@ -1,57 +0,0 @@ -<?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\Tests\Filter; - -use ONGR\ElasticsearchDSL\Filter\MissingFilter; - -class MissingFilterTest extends \PHPUnit_Framework_TestCase -{ - /** - * Tests GetType method. - */ - public function testGetType() - { - $filter = new MissingFilter('', []); - $this->assertEquals('missing', $filter->getType()); - } - - /** - * Data provider to testGetToArray. - * - * @return array - */ - public function getArrayDataProvider() - { - return [ - // Case 1. - ['', [], ['field' => '']], - // Case 2. - ['user', ['bar' => 'foo'], ['field' => 'user', 'bar' => 'foo']], - ]; - } - - /** - * Test for filter toArray() method. - * - * @param string $field - * @param array $parameters - * @param array $expected - * - * @dataProvider getArrayDataProvider - */ - public function testToArray($field, $parameters, $expected) - { - $filter = new MissingFilter($field, $parameters); - $result = $filter->toArray(); - $this->assertEquals($expected, $result); - } -} diff --git a/tests/Filter/NestedFilterTest.php b/tests/Filter/NestedFilterTest.php deleted file mode 100644 index 361a0279bd90d3663ba36939e3906214795f7b1f..0000000000000000000000000000000000000000 --- a/tests/Filter/NestedFilterTest.php +++ /dev/null @@ -1,79 +0,0 @@ -<?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\Tests\Filter; - -use ONGR\ElasticsearchDSL\Filter\NestedFilter; -use ONGR\ElasticsearchDSL\Filter\TermFilter; -use ONGR\ElasticsearchDSL\Filter\TermsFilter; - -class NestedFilterTest extends \PHPUnit_Framework_TestCase -{ - /** - * Tests GetType method. - */ - public function testGetType() - { - $filter = new NestedFilter('', new TermFilter('foo', 'bar')); - $this->assertEquals('nested', $filter->getType()); - } - - /** - * Data provider to testGetToArray. - * - * @return array - */ - public function getArrayDataProvider() - { - $filter = [ - 'terms' => [ - 'foo' => 'bar', - ], - ]; - - return [ - // Case #0 Basic filter. - [ - 'product.sub_item', - [], - ['path' => 'product.sub_item', 'filter' => $filter], - ], - // Case #1 with parameters. - [ - 'product.sub_item', - ['_cache' => true, '_name' => 'named_result'], - [ - 'path' => 'product.sub_item', - 'filter' => $filter, - '_cache' => true, - '_name' => 'named_result', - ], - ], - ]; - } - - /** - * Test for filter toArray() method. - * - * @param string $path - * @param array $parameters - * @param array $expected - * - * @dataProvider getArrayDataProvider - */ - public function testToArray($path, $parameters, $expected) - { - $query = new TermsFilter('foo', 'bar'); - $filter = new NestedFilter($path, $query, $parameters); - $result = $filter->toArray(); - $this->assertEquals($expected, $result); - } -} diff --git a/tests/Filter/NotFilterTest.php b/tests/Filter/NotFilterTest.php deleted file mode 100644 index c35e234631e77f3b56c3800b4c70031ad2dfeafe..0000000000000000000000000000000000000000 --- a/tests/Filter/NotFilterTest.php +++ /dev/null @@ -1,95 +0,0 @@ -<?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\Tests\Filter; - -use ONGR\ElasticsearchDSL\Filter\NotFilter; - -class NotFilterTest extends \PHPUnit_Framework_TestCase -{ - /** - * Tests GetType method. - */ - public function testGetType() - { - $filter = new NotFilter(); - $this->assertEquals('not', $filter->getType()); - } - - /** - * Data provider for testToArray function. - * - * @return array - */ - public function getArrayDataProvider() - { - $mockBuilder = $this->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface') - ->getMock(); - $mockBuilder->expects($this->any()) - ->method('getType') - ->willReturn('range'); - $mockBuilder->expects($this->any()) - ->method('toArray') - ->willReturn(['postDate' => ['from' => '2010-03-01', 'to' => '2010-04-01']]); - - return [ - // Case #1. - [ - $mockBuilder, - [], - [ - 'filter' => [ - 'range' => [ - 'postDate' => [ - 'from' => '2010-03-01', - 'to' => '2010-04-01', - ], - ], - ], - ], - ], - // Case #2. - [ - $mockBuilder, - [ - 'type' => 'acme', - ], - [ - 'filter' => [ - 'range' => [ - 'postDate' => [ - 'from' => '2010-03-01', - 'to' => '2010-04-01', - ], - ], - ], - 'type' => 'acme', - ], - ], - ]; - } - - /** - * Test for filter toArray() method. - * - * @param BuilderInterface $filter Filter. - * @param array $parameters Optional parameters. - * @param array $expected Expected values. - * - * @dataProvider getArrayDataProvider - */ - public function testToArrayMethod($filter, $parameters, $expected) - { - $filter = new NotFilter($filter, $parameters); - $result = $filter->toArray(); - $this->assertEquals($expected, $filter->toArray()); - } -} diff --git a/tests/Filter/OrFilterTest.php b/tests/Filter/OrFilterTest.php deleted file mode 100644 index 94682db0356ae78c04b73528897ddc2faa32c654..0000000000000000000000000000000000000000 --- a/tests/Filter/OrFilterTest.php +++ /dev/null @@ -1,131 +0,0 @@ -<?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\Tests\Filter; - -use ONGR\ElasticsearchDSL\Filter\OrFilter; - -class OrFilterTest extends \PHPUnit_Framework_TestCase -{ - /** - * Tests GetType method. - */ - public function testGetType() - { - $filter = new OrFilter(); - $result = $filter->getType(); - $this->assertEquals('or', $result); - } - - /** - * Data provider for testToArray function. - * - * @return array - */ - public function getArrayDataProvider() - { - $mockBuilderFirstFilter = $this->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface') - ->getMock(); - $mockBuilderFirstFilter->expects($this->any()) - ->method('getType') - ->willReturn('term'); - $mockBuilderFirstFilter->expects($this->any()) - ->method('toArray') - ->willReturn(['test_field' => ['test_value' => 'test']]); - - $mockBuilderSecondFilter = $this->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface') - ->getMock(); - $mockBuilderSecondFilter->expects($this->any()) - ->method('getType') - ->willReturn('prefix'); - $mockBuilderSecondFilter->expects($this->any()) - ->method('toArray') - ->willReturn(['test_field' => ['test_value' => 'test']]); - - return [ - // Case #1. - [ - [$mockBuilderFirstFilter], - [], - [ - [ - 'term' => [ - 'test_field' => [ - 'test_value' => 'test', - ], - ], - ], - ], - ], - // Case #2. - [ - [$mockBuilderFirstFilter, $mockBuilderSecondFilter], - [], - [ - [ - 'term' => [ - 'test_field' => [ - 'test_value' => 'test', - ], - ], - ], - [ - 'prefix' => [ - 'test_field' => [ - 'test_value' => 'test', - ], - ], - ], - ], - ], - // Case #3. - [ - [$mockBuilderFirstFilter, $mockBuilderSecondFilter], - ['type' => 'acme'], - [ - 'filters' => [ - 0 => [ - 'term' => [ - 'test_field' => [ - 'test_value' => 'test', - ], - ], - ], - 1 => [ - 'prefix' => [ - 'test_field' => [ - 'test_value' => 'test', - ], - ], - ], - ], - 'type' => 'acme', - ], - ], - ]; - } - - /** - * Test for filter toArray() method. - * - * @param BuilderInterface[] $filters Array. - * @param array $parameters Optional parameters. - * @param array $expected Expected values. - * - * @dataProvider getArrayDataProvider - */ - public function testToArray($filters, $parameters, $expected) - { - $filter = new OrFilter($filters, $parameters); - $result = $filter->toArray(); - $this->assertEquals($expected, $result); - } -} diff --git a/tests/Filter/PrefixFilterTest.php b/tests/Filter/PrefixFilterTest.php deleted file mode 100644 index cb154d2569ee7c355a801d60c8409be8237c5784..0000000000000000000000000000000000000000 --- a/tests/Filter/PrefixFilterTest.php +++ /dev/null @@ -1,61 +0,0 @@ -<?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\Tests\Filter; - -use ONGR\ElasticsearchDSL\Filter\PrefixFilter; - -class PrefixFilterTest extends \PHPUnit_Framework_TestCase -{ - /** - * Tests GetType method. - */ - public function testGetType() - { - $filter = new PrefixFilter('', '', []); - $result = $filter->getType(); - $this->assertEquals('prefix', $result); - } - - /** - * Data provider to testGetToArray. - * - * @return array - */ - public function getArrayDataProvider() - { - return [ - // Case #1. - ['', '', [], ['' => '']], - // Case #2. - ['prefix', 'foo', [], ['prefix' => 'foo']], - // Case #3. - ['prefix', 'foo', ['type' => 'acme'], ['prefix' => 'foo', 'type' => 'acme']], - ]; - } - - /** - * Test for filter toArray() method. - * - * @param string $field Field name. - * @param string $value Field value. - * @param array $parameters Optional parameters. - * @param array $expected Expected values. - * - * @dataProvider getArrayDataProvider - */ - public function testToArray($field, $value, $parameters, $expected) - { - $filter = new PrefixFilter($field, $value, $parameters); - $result = $filter->toArray(); - $this->assertEquals($expected, $result); - } -} diff --git a/tests/Filter/QueryFilterTest.php b/tests/Filter/QueryFilterTest.php deleted file mode 100644 index ceeeff4681e9548529427c327c05594b68eb12fa..0000000000000000000000000000000000000000 --- a/tests/Filter/QueryFilterTest.php +++ /dev/null @@ -1,67 +0,0 @@ -<?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\Tests\Filter; - -use ONGR\ElasticsearchDSL\Filter\QueryFilter; - -class QueryFilterTest extends \PHPUnit_Framework_TestCase -{ - /** - * Test query with '_cache' parameter. - */ - public function testToArrayWithGetTypeFqueryWithCache() - { - $mockBuilder = $this->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface') - ->getMock(); - $mockBuilder->expects($this->any()) - ->method('getType') - ->willReturn('fquery'); - $filter = new QueryFilter($mockBuilder, ['_cache' => true]); - $result = $filter->toArray(); - $expectedResult = ['query' => ['fquery' => null], '_cache' => true]; - $this->assertEquals($expectedResult, $result); - } - - /** - * Test query without '_cache' parameter. - */ - public function testToArrayWithGetTypeQueryWithoutCache() - { - $mockBuilder = $this->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface') - ->getMock(); - $mockBuilder->expects($this->any()) - ->method('getType') - ->willReturn('query'); - $filter = new QueryFilter($mockBuilder, []); - $result = $filter->toArray(); - $expectedResult = ['query' => null]; - $this->assertEquals($expectedResult, $result); - } - - /** - * Test GetType function, returns 'fquery'. - */ - public function testGetTypeWhenReturnsStringFquery() - { - $filter = new QueryFilter('', ['_cache' => true]); - $this->assertEquals('fquery', $filter->getType()); - } - - /** - * Test GetType function, returns 'query'. - */ - public function testgetTypeWhenReturnsStringQuery() - { - $filter = new QueryFilter('', []); - $this->assertEquals('query', $filter->getType()); - } -} diff --git a/tests/Filter/RangeFilterTest.php b/tests/Filter/RangeFilterTest.php deleted file mode 100644 index ab59eec4b215fe3e13da5141c29aa4a45eea7fdd..0000000000000000000000000000000000000000 --- a/tests/Filter/RangeFilterTest.php +++ /dev/null @@ -1,65 +0,0 @@ -<?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\Tests\Filter; - -use ONGR\ElasticsearchDSL\Filter\RangeFilter; - -class RangeFilterTest extends \PHPUnit_Framework_TestCase -{ - /** - * Tests GetType method. - */ - public function testGetType() - { - $filter = new RangeFilter('', [], []); - $this->assertEquals('range', $filter->getType()); - } - - /** - * Data provider to testGetToArray. - * - * @return array - */ - public function getArrayDataProvider() - { - return [ - // Case #1. - ['', [], [], ['' => []]], - // Case #2. - ['foo', ['gte' => 1, 'lte' => 5], [], ['foo' => ['gte' => 1, 'lte' => 5]]], - // Case #3. - [ - 'test', - ['gte' => 1, 'lte' => 5], - ['type' => 'acme'], - ['test' => ['gte' => 1, 'lte' => 5, 'type' => 'acme']] - ], - ]; - } - - /** - * Test for filter toArray() method. - * - * @param string $field Field name. - * @param array $range Range values. - * @param array $parameters Optional parameters. - * @param array $expected Expected result. - * - * @dataProvider getArrayDataProvider - */ - public function testToArray($field, $range, $parameters, $expected) - { - $filter = new RangeFilter($field, $range, $parameters); - $result = $filter->toArray(); - $this->assertEquals($expected, $result); - } -} diff --git a/tests/Filter/RegexpFilterTest.php b/tests/Filter/RegexpFilterTest.php deleted file mode 100644 index 1f7aa947e3524a4c7d99c94bdf4d1d6bd1a7d2e1..0000000000000000000000000000000000000000 --- a/tests/Filter/RegexpFilterTest.php +++ /dev/null @@ -1,58 +0,0 @@ -<?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\Tests\Filter; - -use ONGR\ElasticsearchDSL\Filter\RegexpFilter; - -class RegexpFilterTest extends \PHPUnit_Framework_TestCase -{ - /** - * Tests GetType method. - */ - public function testGetType() - { - $filter = new RegexpFilter('', '\w', []); - $this->assertEquals('regexp', $filter->getType()); - } - - /** - * Data provider to testGetToArray. - * - * @return array - */ - public function getArrayDataProvider() - { - return [ - // Case #1. - ['', '\w', [], ['' => ['value' => '\w']]], - // Case #2. - ['regexp', '\w', ['flags' => 'foo'], ['regexp' => ['value' => '\w', 'flags' => 'foo']]], - ]; - } - - /** - * Test for filter toArray() method. - * - * @param string $field Field name. - * @param string $regexp Regular expression. - * @param array $parameters Optional parameters. - * @param array $expected Expected values. - * - * @dataProvider getArrayDataProvider - */ - public function testToArray($field, $regexp, $parameters, $expected) - { - $filter = new RegexpFilter($field, $regexp, $parameters); - $result = $filter->toArray(); - $this->assertEquals($expected, $result); - } -} diff --git a/tests/Filter/ScriptFilterTest.php b/tests/Filter/ScriptFilterTest.php deleted file mode 100644 index 514af912f20907672e4f356d1552c1526da01057..0000000000000000000000000000000000000000 --- a/tests/Filter/ScriptFilterTest.php +++ /dev/null @@ -1,59 +0,0 @@ -<?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\Tests\Filter; - -use ONGR\ElasticsearchDSL\Filter\ScriptFilter; - -class ScriptFilterTest extends \PHPUnit_Framework_TestCase -{ - /** - * Tests GetType method. - */ - public function testGetType() - { - $filter = new ScriptFilter(''); - $this->assertEquals('script', $filter->getType()); - } - - /** - * Data provider to testGetToArray. - * - * @return array - */ - public function getArrayDataProvider() - { - return [ - // Case #1. - ['', [], ['script' => '']], - // Case #2. - ['foo', [], ['script' => 'foo']], - // Case #3. - ['foo', ['type' => 'acme'], ['script' => 'foo', 'type' => 'acme']], - ]; - } - - /** - * Test for filter toArray() method. - * - * @param string $script Script. - * @param array $parameters Optional parameters. - * @param array $expected Expected values. - * - * @dataProvider getArrayDataProvider - */ - public function testToArray($script, $parameters, $expected) - { - $filter = new ScriptFilter($script, $parameters); - $result = $filter->toArray(); - $this->assertEquals($expected, $result); - } -} diff --git a/tests/Filter/TermFilterTest.php b/tests/Filter/TermFilterTest.php deleted file mode 100644 index 07b775ef31704f504f03918f956ef3e69052e2c3..0000000000000000000000000000000000000000 --- a/tests/Filter/TermFilterTest.php +++ /dev/null @@ -1,61 +0,0 @@ -<?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\Tests\Filter; - -use ONGR\ElasticsearchDSL\Filter\TermFilter; - -class TermFilterTest extends \PHPUnit_Framework_TestCase -{ - /** - * Tests GetType method. - */ - public function testGetType() - { - $filter = new TermFilter('', '', []); - $result = $filter->getType(); - $this->assertEquals('term', $result); - } - - /** - * Data provider to testGetToArray. - * - * @return array - */ - public function getArrayDataProvider() - { - return [ - // Case #1. - ['', '', [], ['' => '']], - // Case #2. - ['term', 'foo', [], ['term' => 'foo']], - // Case #3. - ['term', 'foo', ['type' => 'acme'], ['term' => 'foo', 'type' => 'acme']], - ]; - } - - /** - * Test for filter toArray() method. - * - * @param string $field Field name. - * @param string $term Field value. - * @param array $parameters Optional parameters. - * @param array $expected Expected values. - * - * @dataProvider getArrayDataProvider - */ - public function testToArray($field, $term, $parameters, $expected) - { - $filter = new TermFilter($field, $term, $parameters); - $result = $filter->toArray(); - $this->assertEquals($expected, $result); - } -} diff --git a/tests/Filter/TermsFilterTest.php b/tests/Filter/TermsFilterTest.php deleted file mode 100644 index 1fd3286f66e31effb6ab9de6517b5e375034165c..0000000000000000000000000000000000000000 --- a/tests/Filter/TermsFilterTest.php +++ /dev/null @@ -1,61 +0,0 @@ -<?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\Tests\Filter; - -use ONGR\ElasticsearchDSL\Filter\TermsFilter; - -class TermsFilterTest extends \PHPUnit_Framework_TestCase -{ - /** - * Tests GetType method. - */ - public function testGetType() - { - $filter = new TermsFilter('', [], []); - $result = $filter->getType(); - $this->assertEquals('terms', $result); - } - - /** - * Data provider to testGetToArray. - * - * @return array - */ - public function getArrayDataProvider() - { - return [ - // Case #1. - ['', [], [], ['' => []]], - // Case #2. - ['tags', ['foo', 'bar'], [], ['tags' => [0 => 'foo', 1 => 'bar']]], - // Case #3. - ['tags', ['foo', 'bar'], ['type' => 'acme'], ['tags' => [0 => 'foo', 1 => 'bar'], 'type' => 'acme']], - ]; - } - - /** - * Test for filter toArray() method. - * - * @param string $field Field name. - * @param array $terms An array of terms. - * @param array $parameters Optional parameters. - * @param array $expected Expected values. - * - * @dataProvider getArrayDataProvider - */ - public function testToArray($field, $terms, $parameters, $expected) - { - $filter = new TermsFilter($field, $terms, $parameters); - $result = $filter->toArray(); - $this->assertEquals($expected, $result); - } -} diff --git a/tests/Filter/TypeFilterTest.php b/tests/Filter/TypeFilterTest.php deleted file mode 100644 index 18ae31589f29becbcb36d857e4f814956eed66fc..0000000000000000000000000000000000000000 --- a/tests/Filter/TypeFilterTest.php +++ /dev/null @@ -1,36 +0,0 @@ -<?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\Tests\Filter; - -use ONGR\ElasticsearchDSL\Filter\TypeFilter; - -class TypeFilterTest extends \PHPUnit_Framework_TestCase -{ - /** - * Tests GetType method. - */ - public function testGetType() - { - $filter = new TypeFilter(''); - $this->assertEquals('type', $filter->getType()); - } - - /** - * Test for filter toArray() method. - */ - public function testToArray() - { - $filter = new TypeFilter('foo'); - $expectedResult = ['value' => 'foo']; - $this->assertEquals($expectedResult, $filter->toArray()); - } -} diff --git a/tests/FilterOrQueryDetectionTraitTest.php b/tests/FilterOrQueryDetectionTraitTest.php deleted file mode 100644 index 9493dcf02176cf388134b2944d635338e0a27500..0000000000000000000000000000000000000000 --- a/tests/FilterOrQueryDetectionTraitTest.php +++ /dev/null @@ -1,69 +0,0 @@ -<?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\Tests\Unit\DSL; - -use ONGR\ElasticsearchDSL\Aggregation\GlobalAggregation; -use ONGR\ElasticsearchDSL\Filter\MatchAllFilter; -use ONGR\ElasticsearchDSL\FilterOrQueryDetectionTrait; -use ONGR\ElasticsearchDSL\Query\MatchAllQuery; - -/** - * Test for FilterOrQueryDetectionTrait. - */ -class FilterOrQueryDetectionTraitTest extends \PHPUnit_Framework_TestCase -{ - /** - * @var FilterOrQueryDetectionTrait - */ - private $mock; - - /** - * {@inheritdoc} - */ - public function setUp() - { - $this->mock = $this->getMockForTrait('ONGR\ElasticsearchDSL\FilterOrQueryDetectionTrait'); - } - - /** - * Tests if setDslType throws exception. - * - * @expectedException \InvalidArgumentException - */ - public function testIfTraitDetectsNotKnowType() - { - $aggregation = new GlobalAggregation('global'); - $this->mock->detectDslType($aggregation); - } - - /** - * Tests if detectDslType detects passed query. - */ - public function testIfTraitDetectsQuery() - { - $query = new MatchAllQuery(); - $result = $this->mock->detectDslType($query); - - $this->assertEquals('query', $result); - } - - /** - * Tests if detectDslType detects passed filter. - */ - public function testIfTraitDetectsFilter() - { - $filter = new MatchAllFilter(); - $result = $this->mock->detectDslType($filter); - - $this->assertEquals('filter', $result); - } -} diff --git a/tests/Query/HasChildQueryTest.php b/tests/Query/HasChildQueryTest.php index da8852af5d3b854b6331cb79071bf0321273fc93..f7c15cf6b5b745e18ce17f9c44e32f0bbe45e3bc 100644 --- a/tests/Query/HasChildQueryTest.php +++ b/tests/Query/HasChildQueryTest.php @@ -20,8 +20,8 @@ class HasChildQueryTest extends \PHPUnit_Framework_TestCase */ public function testConstructor() { - $childQuery = $this->getMock('ONGR\ElasticsearchDSL\BuilderInterface'); - $query = new HasChildQuery('test_type', $childQuery, ['test_parameter1']); + $parentQuery = $this->getMock('ONGR\ElasticsearchDSL\BuilderInterface'); + $query = new HasChildQuery('test_type', $parentQuery, ['test_parameter1']); $this->assertEquals(['test_parameter1'], $query->getParameters()); } } diff --git a/tests/SearchEndpoint/FilterEndpointTest.php b/tests/SearchEndpoint/FilterEndpointTest.php index c8c8eb8e75830902953775b61e1961a3400e440b..86425f6deee8f4d0635f6543893c395ef2fa8855 100644 --- a/tests/SearchEndpoint/FilterEndpointTest.php +++ b/tests/SearchEndpoint/FilterEndpointTest.php @@ -11,7 +11,6 @@ namespace ONGR\ElasticsearchDSL\Tests\Unit\SearchEndpoint; -use ONGR\ElasticsearchDSL\Query\FilteredQuery; use ONGR\ElasticsearchDSL\Query\MatchAllQuery; use ONGR\ElasticsearchDSL\SearchEndpoint\FilterEndpoint; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; @@ -53,20 +52,16 @@ class FilterEndpointTest extends \PHPUnit_Framework_TestCase 'Symfony\Component\Serializer\Normalizer\NormalizerInterface' ); $this->assertNull($instance->normalize($normalizerInterface)); - $this->assertFalse($instance->hasReference('filtered_query')); + $this->assertFalse($instance->hasReference('filter_query')); $matchAllFilter = new MatchAllQuery(); $instance->add($matchAllFilter); $this->assertNull($instance->normalize($normalizerInterface)); - $this->assertTrue($instance->hasReference('filtered_query')); - - /** @var FilteredQuery $reference */ - $reference = $instance->getReference('filtered_query'); - $this->assertInstanceOf('ONGR\ElasticsearchDSL\Query\FilteredQuery', $reference); + $this->assertTrue($instance->hasReference('filter_query')); /** @var \ONGR\ElasticsearchDSL\Query\BoolQuery $bool */ - $bool = $reference->getFilter(); + $bool = $instance->getReference('filter_query'); $this->assertInstanceOf('ONGR\ElasticsearchDSL\Query\BoolQuery', $bool); $must = $bool->getQueries('must'); diff --git a/tests/SearchTest.php b/tests/SearchTest.php index 1b72a3964bff4ca4cdddb1493e9b558b7960e6c3..d4f50b5289c314a26faf9fb6aac4ca8f8af22f0b 100644 --- a/tests/SearchTest.php +++ b/tests/SearchTest.php @@ -11,6 +11,8 @@ namespace ONGR\ElasticsearchDSL\Tests\Unit\DSL; +use ONGR\ElasticsearchDSL\Query\MissingQuery; +use ONGR\ElasticsearchDSL\Query\TermQuery; use ONGR\ElasticsearchDSL\Search; /** @@ -183,4 +185,89 @@ class SearchTest extends \PHPUnit_Framework_TestCase $search->getQueryParams() ); } + + /** + * Data provider for testToArray(). + * + * @return array + */ + public function getTestToArrayData() + { + $cases = []; + + $cases['empty_search'] = [ + [], + new Search(), + ]; + + $cases['single_term_query'] = [ + [ + 'query' => [ + 'bool' => [ + 'must' => [ + ['term' => ['foo' => 'bar']], + ], + ], + ], + ], + (new Search())->addQuery(new TermQuery('foo', 'bar')), + ]; + + $cases['single_term_filter'] = [ + [ + 'query' => [ + 'bool' => [ + 'filter' => [ + [ + 'bool' => [ + 'must' => [ + ['term' => ['foo' => 'bar']], + ], + ], + ], + ], + ], + ], + ], + (new Search())->addFilter(new TermQuery('foo', 'bar')), + ]; + + $cases['single_query_query_and_filter'] = [ + [ + 'query' => [ + 'bool' => [ + 'must' => [ + ['term' => ['foo' => 'bar']], + ], + 'filter' => [ + [ + 'bool' => [ + 'must' => [ + ['missing' => ['field' => 'baz']], + ], + ], + ], + ], + ], + ], + ], + (new Search())->addQuery(new TermQuery('foo', 'bar'))->addFilter(new MissingQuery('baz')), + ]; + + return $cases; + } + + /** + * @param array $expected + * @param Search $search + * + * @dataProvider getTestToArrayData() + */ + public function testToArray($expected, $search) + { + $this->assertEquals($expected, $search->toArray()); + + // Double check + $this->assertEquals($expected, $search->toArray()); + } }