Skip to content
This repository was archived by the owner on Nov 4, 2021. It is now read-only.

Commit 9f34529

Browse files
committed
geo spatial filtres
1 parent fcc5857 commit 9f34529

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,9 @@ whereNotBetween($field, $value) | whereNotBetween('price', [100, 200]) | Checks
398398
whereExists($field) | whereExists('unemployed') | Checks if a value is defined.
399399
whereNotExists($field) | whereNotExists('unemployed') | Checks if a value isn't defined.
400400
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/5.2/query-dsl-regexp-query.html#regexp-syntax) you can find more about syntax.
401+
whereGeoDistance($field, $value, $distance) | whereGeoDistance('location', [-70, 40], 1000) | 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.
402+
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.
403+
whereGeoPolygon($field, array $points) | whereGeoPolygon('location', [[-70, 40],[-80, 30],[-90, 20]]) | Filters records within given polygon. [Here](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-polygon-query.html) you can find more about syntax.
401404

402405
In most cases it's better to use raw fields to filter records, i.e. not analyzed fields.
403406

src/Builders/FilterBuilder.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,46 @@ public function whereRegexp($field, $value, $flags = 'ALL')
114114
return $this;
115115
}
116116

117+
/**
118+
* https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html
119+
* @param string $field
120+
* @param string $value
121+
* @param array|string $distance
122+
* @return $this
123+
*/
124+
public function whereGeoDistance($field, $value, $distance)
125+
{
126+
$this->wheres['must'][] = ['geo_distance' => ['distance' => $distance, $field => $value]];
127+
128+
return $this;
129+
}
130+
131+
/**
132+
* https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-bounding-box-query.html
133+
* @param string $field
134+
* @param array $value
135+
* @return $this
136+
*/
137+
public function whereGeoBoundingBox($field, array $value)
138+
{
139+
$this->wheres['must'][] = ['geo_bounding_box' => [$field => $value]];
140+
141+
return $this;
142+
}
143+
144+
/**
145+
* https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-polygon-query.html
146+
* @param string $field
147+
* @param array $points
148+
* @return $this
149+
*/
150+
public function whereGeoPolygon($field, array $points)
151+
{
152+
$this->wheres['must'][] = ['geo_polygon' => [$field => ['points' => $points]]];
153+
154+
return $this;
155+
}
156+
117157
public function orderBy($column, $direction = 'asc')
118158
{
119159
$this->orders[] = [$column => strtolower($direction) == 'asc' ? 'asc' : 'desc'];

0 commit comments

Comments
 (0)