From 167d02a7ce49ea660423300657468ece2c8e336d Mon Sep 17 00:00:00 2001 From: Madalin Ignisca Date: Tue, 20 Apr 2021 15:40:29 +0200 Subject: [PATCH 1/2] Adds match filter It is compatible with ES 6.x. --- src/Builders/FilterBuilder.php | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/Builders/FilterBuilder.php b/src/Builders/FilterBuilder.php index 792378a..2c183d3 100644 --- a/src/Builders/FilterBuilder.php +++ b/src/Builders/FilterBuilder.php @@ -275,6 +275,42 @@ public function whereNotExists($field) return $this; } + /** + * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-match-query.html Match query + * + * @param string $field + * @param string $value + * @return $this + */ + public function whereMatch($field, $value) + { + $this->wheres['must'][] = [ + 'match' => [ + $field => $value, + ], + ]; + + return $this; + } + + /** + * @see https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-match-query.html Match query + * + * @param string $field + * @param string $value + * @return $this + */ + public function whereNotMatch($field, $value) + { + $this->wheres['must_not'][] = [ + 'match' => [ + $field => $value, + ], + ]; + + return $this; + } + /** * Add a whereRegexp condition. * From 376df9c0fcb44ae93197691a2d0e18d2d079c01b Mon Sep 17 00:00:00 2001 From: Madalin Ignisca Date: Tue, 20 Apr 2021 16:55:50 +0200 Subject: [PATCH 2/2] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f0f2fe8..f14ffcb 100644 --- a/README.md +++ b/README.md @@ -440,7 +440,9 @@ whereNotIn($field, $value) | whereNotIn('id', [1, 2, 3]) | Checks if a value isn whereBetween($field, $value) | whereBetween('price', [100, 200]) | Checks if a value is in a range. whereNotBetween($field, $value) | whereNotBetween('price', [100, 200]) | Checks if a value isn't in a range. whereExists($field) | whereExists('unemployed') | Checks if a value is defined. -whereNotExists($field) | whereNotExists('unemployed') | Checks if a value isn't defined. +whereNotExists($field) | whereNotExists('unemployed') | Checks if a value isn't define. +whereMatch($field, $value) | whereMatch('tags', 'travel') | Filters records matching exact value. [Here](https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-match-query.html) you can find more about syntax. +whereNotMatch($field, $value) | whereNotMatch('tags', 'travel') | Filters records not matching exact value. [Here](https://www.elastic.co/guide/en/elasticsearch/reference/6.8/query-dsl-match-query.html) you can find more about syntax. whereRegexp($field, $value, $flags = 'ALL') | whereRegexp('name.raw', 'A.+') | Filters records according to a given regular expression. [Here](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html#regexp-syntax) you can find more about syntax. whereGeoDistance($field, $value, $distance) | whereGeoDistance('location', [-70, 40], '1000m') | Filters records according to given point and distance from it. [Here](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html) you can find more about syntax. whereGeoBoundingBox($field, array $value) | whereGeoBoundingBox('location', ['top_left' => [-74.1, 40.73], 'bottom_right' => [-71.12, 40.01]]) | Filters records within given boundings. [Here](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-bounding-box-query.html) you can find more about syntax.