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    const DISTANCE_TYPE_ARC = 'arc';
15    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     * @param string $distance
35     *
36     * @return $this
37     */
38    public function setDistance(string $distance): self
39    {
40        $this->setParam('distance', $distance);
41
42        return $this;
43    }
44
45    /**
46     * See DISTANCE_TYPE_* constants.
47     *
48     * @param string $distanceType, default arc
49     *
50     * @return $this
51     */
52    public function setDistanceType(string $distanceType = self::DISTANCE_TYPE_ARC): self
53    {
54        $this->setParam('distance_type', $distanceType);
55
56        return $this;
57    }
58}
59