1<?php
2
3namespace Elastica\Query;
4
5/**
6 * Geo distance query.
7 *
8 * @author Nicolas Ruflin <spam@ruflin.com>
9 *
10 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html
11 */
12class GeoDistance extends AbstractGeoDistance
13{
14    public const DISTANCE_TYPE_ARC = 'arc';
15    public const DISTANCE_TYPE_PLANE = 'plane';
16
17    /**
18     * Create GeoDistance object.
19     *
20     * @param string       $key      Key
21     * @param array|string $location Location as array or geohash: array('lat' => 48.86, 'lon' => 2.35) OR 'drm3btev3e86'
22     * @param string       $distance Distance
23     *
24     * @throws \Elastica\Exception\InvalidException
25     */
26    public function __construct(string $key, $location, string $distance)
27    {
28        parent::__construct($key, $location);
29
30        $this->setDistance($distance);
31    }
32
33    /**
34     * @return $this
35     */
36    public function setDistance(string $distance): self
37    {
38        $this->setParam('distance', $distance);
39
40        return $this;
41    }
42
43    /**
44     * See DISTANCE_TYPE_* constants.
45     *
46     * @param string $distanceType, default arc
47     *
48     * @return $this
49     */
50    public function setDistanceType(string $distanceType = self::DISTANCE_TYPE_ARC): self
51    {
52        $this->setParam('distance_type', $distanceType);
53
54        return $this;
55    }
56}
57