From 034fde02765bca2bff540e69d2e95673d41e3837 Mon Sep 17 00:00:00 2001 From: Mantas Varatiejus <mantas.varatiejus@nfq.com> Date: Thu, 21 Jan 2016 11:35:32 +0200 Subject: [PATCH] Remove filters --- CHANGELOG.md | 1 + README.md | 9 +- docs/Filter/And.md | 51 -------- docs/Filter/Bool.md | 96 -------------- docs/Filter/Exists.md | 31 ----- docs/Filter/GeoBoundingBox.md | 90 -------------- docs/Filter/GeoDistance.md | 43 ------- docs/Filter/GeoDistanceRange.md | 45 ------- docs/Filter/GeoPolygon.md | 48 ------- docs/Filter/GeoShape.md | 86 ------------- docs/Filter/GeohashCell.md | 51 -------- docs/Filter/HasChild.md | 38 ------ docs/Filter/HasParent.md | 39 ------ docs/Filter/Ids.md | 32 ----- docs/Filter/Indices.md | 45 ------- docs/Filter/Limit.md | 35 ------ docs/Filter/MatchAll.md | 28 ----- docs/Filter/Missing.md | 28 ----- docs/Filter/Nested.md | 56 --------- docs/Filter/Not.md | 50 -------- docs/Filter/Or.md | 49 -------- docs/Filter/Post.md | 69 ----------- docs/Filter/Prefix.md | 28 ----- docs/Filter/Query.md | 33 ----- docs/Filter/Range.md | 33 ----- docs/Filter/Regexp.md | 32 ----- docs/Filter/Script.md | 30 ----- docs/Filter/Term.md | 28 ----- docs/Filter/Terms.md | 28 ----- docs/Filter/Type.md | 28 ----- docs/Filter/index.md | 65 ---------- docs/index.md | 2 - src/Filter/AndFilter.php | 105 ---------------- src/Filter/BoolFilter.php | 30 ----- src/Filter/ExistsFilter.php | 30 ----- src/Filter/GeoBoundingBoxFilter.php | 28 ----- src/Filter/GeoDistanceFilter.php | 28 ----- src/Filter/GeoDistanceRangeFilter.php | 28 ----- src/Filter/GeoPolygonFilter.php | 28 ----- src/Filter/GeoShapeFilter.php | 28 ----- src/Filter/GeohashCellFilter.php | 28 ----- src/Filter/HasChildFilter.php | 56 --------- src/Filter/HasParentFilter.php | 56 --------- src/Filter/IdsFilter.php | 28 ----- src/Filter/IndicesFilter.php | 86 ------------- src/Filter/LimitFilter.php | 30 ----- src/Filter/MatchAllFilter.php | 30 ----- src/Filter/MissingFilter.php | 28 ----- src/Filter/NestedFilter.php | 39 ------ src/Filter/NotFilter.php | 90 -------------- src/Filter/OrFilter.php | 35 ------ src/Filter/PrefixFilter.php | 41 ------ src/Filter/QueryFilter.php | 73 ----------- src/Filter/RangeFilter.php | 39 ------ src/Filter/RegexpFilter.php | 79 ------------ src/Filter/ScriptFilter.php | 67 ---------- src/Filter/TermFilter.php | 60 --------- src/Filter/TermsFilter.php | 28 ----- src/Filter/TypeFilter.php | 30 ----- src/FilterOrQueryDetectionTrait.php | 45 ------- src/Query/ConstantScoreQuery.php | 4 +- tests/Aggregation/FilterAggregationTest.php | 4 +- tests/Filter/AndFilterTest.php | 131 -------------------- tests/Filter/ExistsFilterTest.php | 38 ------ tests/Filter/GeoBoundingBoxFilterTest.php | 97 --------------- tests/Filter/GeoDistanceFilterTest.php | 72 ----------- tests/Filter/GeoDistanceRangeFilterTest.php | 72 ----------- tests/Filter/GeoPolygonFilterTest.php | 98 --------------- tests/Filter/HasChildFilterTest.php | 85 ------------- tests/Filter/HasParentFilterTest.php | 85 ------------- tests/Filter/IdsFilterTest.php | 60 --------- tests/Filter/IndicesFilterTest.php | 108 ---------------- tests/Filter/LimitFilterTest.php | 36 ------ tests/Filter/MatchAllFilterTest.php | 38 ------ tests/Filter/MissingFilterTest.php | 57 --------- tests/Filter/NestedFilterTest.php | 79 ------------ tests/Filter/NotFilterTest.php | 95 -------------- tests/Filter/OrFilterTest.php | 131 -------------------- tests/Filter/PrefixFilterTest.php | 61 --------- tests/Filter/QueryFilterTest.php | 67 ---------- tests/Filter/RangeFilterTest.php | 65 ---------- tests/Filter/RegexpFilterTest.php | 58 --------- tests/Filter/ScriptFilterTest.php | 59 --------- tests/Filter/TermFilterTest.php | 61 --------- tests/Filter/TermsFilterTest.php | 61 --------- tests/Filter/TypeFilterTest.php | 36 ------ tests/FilterOrQueryDetectionTraitTest.php | 69 ----------- tests/Query/HasChildQueryTest.php | 4 +- 88 files changed, 11 insertions(+), 4420 deletions(-) delete mode 100644 docs/Filter/And.md delete mode 100644 docs/Filter/Bool.md delete mode 100644 docs/Filter/Exists.md delete mode 100644 docs/Filter/GeoBoundingBox.md delete mode 100644 docs/Filter/GeoDistance.md delete mode 100644 docs/Filter/GeoDistanceRange.md delete mode 100644 docs/Filter/GeoPolygon.md delete mode 100644 docs/Filter/GeoShape.md delete mode 100644 docs/Filter/GeohashCell.md delete mode 100644 docs/Filter/HasChild.md delete mode 100644 docs/Filter/HasParent.md delete mode 100644 docs/Filter/Ids.md delete mode 100644 docs/Filter/Indices.md delete mode 100644 docs/Filter/Limit.md delete mode 100644 docs/Filter/MatchAll.md delete mode 100644 docs/Filter/Missing.md delete mode 100644 docs/Filter/Nested.md delete mode 100644 docs/Filter/Not.md delete mode 100644 docs/Filter/Or.md delete mode 100644 docs/Filter/Post.md delete mode 100644 docs/Filter/Prefix.md delete mode 100644 docs/Filter/Query.md delete mode 100644 docs/Filter/Range.md delete mode 100644 docs/Filter/Regexp.md delete mode 100644 docs/Filter/Script.md delete mode 100644 docs/Filter/Term.md delete mode 100644 docs/Filter/Terms.md delete mode 100644 docs/Filter/Type.md delete mode 100644 docs/Filter/index.md delete mode 100644 src/Filter/AndFilter.php delete mode 100644 src/Filter/BoolFilter.php delete mode 100644 src/Filter/ExistsFilter.php delete mode 100644 src/Filter/GeoBoundingBoxFilter.php delete mode 100644 src/Filter/GeoDistanceFilter.php delete mode 100644 src/Filter/GeoDistanceRangeFilter.php delete mode 100644 src/Filter/GeoPolygonFilter.php delete mode 100644 src/Filter/GeoShapeFilter.php delete mode 100644 src/Filter/GeohashCellFilter.php delete mode 100644 src/Filter/HasChildFilter.php delete mode 100644 src/Filter/HasParentFilter.php delete mode 100644 src/Filter/IdsFilter.php delete mode 100644 src/Filter/IndicesFilter.php delete mode 100644 src/Filter/LimitFilter.php delete mode 100644 src/Filter/MatchAllFilter.php delete mode 100644 src/Filter/MissingFilter.php delete mode 100644 src/Filter/NestedFilter.php delete mode 100644 src/Filter/NotFilter.php delete mode 100644 src/Filter/OrFilter.php delete mode 100644 src/Filter/PrefixFilter.php delete mode 100644 src/Filter/QueryFilter.php delete mode 100644 src/Filter/RangeFilter.php delete mode 100644 src/Filter/RegexpFilter.php delete mode 100644 src/Filter/ScriptFilter.php delete mode 100644 src/Filter/TermFilter.php delete mode 100644 src/Filter/TermsFilter.php delete mode 100644 src/Filter/TypeFilter.php delete mode 100644 src/FilterOrQueryDetectionTrait.php delete mode 100644 tests/Filter/AndFilterTest.php delete mode 100644 tests/Filter/ExistsFilterTest.php delete mode 100644 tests/Filter/GeoBoundingBoxFilterTest.php delete mode 100644 tests/Filter/GeoDistanceFilterTest.php delete mode 100644 tests/Filter/GeoDistanceRangeFilterTest.php delete mode 100644 tests/Filter/GeoPolygonFilterTest.php delete mode 100644 tests/Filter/HasChildFilterTest.php delete mode 100644 tests/Filter/HasParentFilterTest.php delete mode 100644 tests/Filter/IdsFilterTest.php delete mode 100644 tests/Filter/IndicesFilterTest.php delete mode 100644 tests/Filter/LimitFilterTest.php delete mode 100644 tests/Filter/MatchAllFilterTest.php delete mode 100644 tests/Filter/MissingFilterTest.php delete mode 100644 tests/Filter/NestedFilterTest.php delete mode 100644 tests/Filter/NotFilterTest.php delete mode 100644 tests/Filter/OrFilterTest.php delete mode 100644 tests/Filter/PrefixFilterTest.php delete mode 100644 tests/Filter/QueryFilterTest.php delete mode 100644 tests/Filter/RangeFilterTest.php delete mode 100644 tests/Filter/RegexpFilterTest.php delete mode 100644 tests/Filter/ScriptFilterTest.php delete mode 100644 tests/Filter/TermFilterTest.php delete mode 100644 tests/Filter/TermsFilterTest.php delete mode 100644 tests/Filter/TypeFilterTest.php delete mode 100644 tests/FilterOrQueryDetectionTraitTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 340e0e4..9796b50 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 4e6aa41..db17faf 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/Filter/And.md b/docs/Filter/And.md deleted file mode 100644 index b514f8e..0000000 --- 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 a9efc2b..0000000 --- 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 c54434e..0000000 --- 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 2d3e23e..0000000 --- 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 8c2ec11..0000000 --- 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 ccb692c..0000000 --- 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 98631f1..0000000 --- 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 e44d816..0000000 --- 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 25edda7..0000000 --- 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 7ea6691..0000000 --- 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 53bd7fa..0000000 --- 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 e2bcfb6..0000000 --- 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 caacb11..0000000 --- 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 567be0f..0000000 --- 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 3d8d9ed..0000000 --- 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 f963111..0000000 --- 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 151ac12..0000000 --- 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 9fc9697..0000000 --- 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 34a666a..0000000 --- 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 c976c26..0000000 --- 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 75e541c..0000000 --- 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 0889b83..0000000 --- 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 e2a2315..0000000 --- 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 99e8c03..0000000 --- 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 8d35342..0000000 --- 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 15a482a..0000000 --- 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 6b595ba..0000000 --- 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 91915ef..0000000 --- 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 d07b941..0000000 --- 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/index.md b/docs/index.md index 7ff3902..937fd46 100644 --- a/docs/index.md +++ b/docs/index.md @@ -9,8 +9,6 @@ Everything starts from the `Search` object. We recommend first to take a look at - [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/Filter/AndFilter.php b/src/Filter/AndFilter.php deleted file mode 100644 index 3be326c..0000000 --- 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 a3699a0..0000000 --- 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 31f4894..0000000 --- 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 1aacf8b..0000000 --- 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 0de010f..0000000 --- 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 44a24f9..0000000 --- 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 3340aea..0000000 --- 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 d783268..0000000 --- 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 768f02b..0000000 --- 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 de79c65..0000000 --- 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 90212bc..0000000 --- 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 64a195e..0000000 --- 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 a2f829a..0000000 --- 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 b870f8a..0000000 --- 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 30c15c2..0000000 --- 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 a1102dd..0000000 --- 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 1202802..0000000 --- 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 d43653f..0000000 --- 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 834b99e..0000000 --- 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 78d15ec..0000000 --- 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 f9f23cb..0000000 --- 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 c891684..0000000 --- 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 1bc03ec..0000000 --- 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 5b751cd..0000000 --- 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 fade730..0000000 --- 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 c42fff8..0000000 --- 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 018a59d..0000000 --- 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 1d3f15e..0000000 --- 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 d4662d2..bb3dc5a 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/tests/Aggregation/FilterAggregationTest.php b/tests/Aggregation/FilterAggregationTest.php index 9416780..6f8fe99 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/Filter/AndFilterTest.php b/tests/Filter/AndFilterTest.php deleted file mode 100644 index e768a50..0000000 --- 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 fa46ac6..0000000 --- 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 69abbc9..0000000 --- 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 f76eb3b..0000000 --- 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 6908711..0000000 --- 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 97c3c7e..0000000 --- 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 0be852a..0000000 --- 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 d0ad8a5..0000000 --- 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 84ff9e9..0000000 --- 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 d6c6027..0000000 --- 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 41b963f..0000000 --- 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 eb2b2f6..0000000 --- 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 7ebab6b..0000000 --- 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 361a027..0000000 --- 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 c35e234..0000000 --- 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 94682db..0000000 --- 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 cb154d2..0000000 --- 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 ceeeff4..0000000 --- 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 ab59eec..0000000 --- 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 1f7aa94..0000000 --- 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 514af91..0000000 --- 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 07b775e..0000000 --- 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 1fd3286..0000000 --- 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 18ae315..0000000 --- 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 9493dcf..0000000 --- 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 da8852a..f7c15cf 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()); } } -- GitLab