summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/lib/Elastica/Facet/GeoDistance.php
blob: 664d33a604af2e8986d960e5e7ad715cd98e98a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace Elastica\Facet;

/**
 * Implements the Geo Distance facet.
 *
 * @author Gerard A. Matthew  <gerard.matthew@gmail.com>
 *
 * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-facets-geo-distance-facet.html
 * @deprecated Facets are deprecated and will be removed in a future release. You are encouraged to migrate to aggregations instead.
 */
class GeoDistance extends AbstractFacet
{
    /**
     * Sets the ranges for the facet all at once.
     * Sample ranges:
     * array (
     * array('to' => 50),
     * array('from' => 20, 'to' => 70),
     * array('from' => 70, 'to' => 120),
     * array('from' => 150)
     * ).
     *
     * @param array $ranges Numerical array with range definitions.
     *
     * @return $this
     */
    public function setRanges(array $ranges)
    {
        return $this->setParam('ranges', $ranges);
    }

    /**
     * Set the relative GeoPoint for the facet.
     *
     * @param string $typeField index type and field e.g foo.bar
     * @param float  $latitude
     * @param float  $longitude
     *
     * @return $this
     */
    public function setGeoPoint($typeField, $latitude, $longitude)
    {
        return $this->setParam($typeField, array(
            'lat' => $latitude,
            'lon' => $longitude,
        ));
    }

    /**
     * Creates the full facet definition, which includes the basic
     * facet definition of the parent.
     *
     * @see \Elastica\Facet\AbstractFacet::toArray()
     *
     * @throws \Elastica\Exception\InvalidException When the right fields haven't been set.
     *
     * @return array
     */
    public function toArray()
    {
        /*
         * Set the geo_distance in the abstract as param.
         */
        $this->_setFacetParam('geo_distance', $this->_params);

        return parent::toArray();
    }
}