| @@ 22-77 (lines=56) @@ | ||
| 19 | * |
|
| 20 | * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html |
|
| 21 | */ |
|
| 22 | class GeoDistanceQuery implements BuilderInterface |
|
| 23 | { |
|
| 24 | use ParametersTrait; |
|
| 25 | ||
| 26 | /** |
|
| 27 | * @var string |
|
| 28 | */ |
|
| 29 | private $field; |
|
| 30 | ||
| 31 | /** |
|
| 32 | * @var string |
|
| 33 | */ |
|
| 34 | private $distance; |
|
| 35 | ||
| 36 | /** |
|
| 37 | * @var mixed |
|
| 38 | */ |
|
| 39 | private $location; |
|
| 40 | ||
| 41 | /** |
|
| 42 | * @param string $field |
|
| 43 | * @param string $distance |
|
| 44 | * @param mixed $location |
|
| 45 | * @param array $parameters |
|
| 46 | */ |
|
| 47 | public function __construct($field, $distance, $location, array $parameters = []) |
|
| 48 | { |
|
| 49 | $this->field = $field; |
|
| 50 | $this->distance = $distance; |
|
| 51 | $this->location = $location; |
|
| 52 | ||
| 53 | $this->setParameters($parameters); |
|
| 54 | } |
|
| 55 | ||
| 56 | /** |
|
| 57 | * {@inheritdoc} |
|
| 58 | */ |
|
| 59 | public function getType() |
|
| 60 | { |
|
| 61 | return 'geo_distance'; |
|
| 62 | } |
|
| 63 | ||
| 64 | /** |
|
| 65 | * {@inheritdoc} |
|
| 66 | */ |
|
| 67 | public function toArray() |
|
| 68 | { |
|
| 69 | $query = [ |
|
| 70 | 'distance' => $this->distance, |
|
| 71 | $this->field => $this->location, |
|
| 72 | ]; |
|
| 73 | $output = $this->processArray($query); |
|
| 74 | ||
| 75 | return [$this->getType() => $output]; |
|
| 76 | } |
|
| 77 | } |
|
| 78 | ||
| @@ 22-74 (lines=53) @@ | ||
| 19 | * |
|
| 20 | * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-range-query.html |
|
| 21 | */ |
|
| 22 | class GeoDistanceRangeQuery implements BuilderInterface |
|
| 23 | { |
|
| 24 | use ParametersTrait; |
|
| 25 | ||
| 26 | /** |
|
| 27 | * @var string |
|
| 28 | */ |
|
| 29 | private $field; |
|
| 30 | ||
| 31 | /** |
|
| 32 | * @var array |
|
| 33 | */ |
|
| 34 | private $range; |
|
| 35 | ||
| 36 | /** |
|
| 37 | * @var mixed |
|
| 38 | */ |
|
| 39 | private $location; |
|
| 40 | ||
| 41 | /** |
|
| 42 | * @param string $field |
|
| 43 | * @param array $range |
|
| 44 | * @param mixed $location |
|
| 45 | * @param array $parameters |
|
| 46 | */ |
|
| 47 | public function __construct($field, $range, $location, array $parameters = []) |
|
| 48 | { |
|
| 49 | $this->field = $field; |
|
| 50 | $this->range = $range; |
|
| 51 | $this->location = $location; |
|
| 52 | ||
| 53 | $this->setParameters($parameters); |
|
| 54 | } |
|
| 55 | ||
| 56 | /** |
|
| 57 | * {@inheritdoc} |
|
| 58 | */ |
|
| 59 | public function getType() |
|
| 60 | { |
|
| 61 | return 'geo_distance_range'; |
|
| 62 | } |
|
| 63 | ||
| 64 | /** |
|
| 65 | * {@inheritdoc} |
|
| 66 | */ |
|
| 67 | public function toArray() |
|
| 68 | { |
|
| 69 | $query = $this->range + [$this->field => $this->location]; |
|
| 70 | $output = $this->processArray($query); |
|
| 71 | ||
| 72 | return [$this->getType() => $output]; |
|
| 73 | } |
|
| 74 | } |
|
| 75 | ||