summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/lib/Elastica/Facet/Histogram.php
blob: 1b76ea8938eb8f5610711e732a3e07133595cc9b (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
namespace Elastica\Facet;

/**
 * Implements the Histogram facet.
 *
 * @author Raul Martinez Jr  <juneym@gmail.com>
 *
 * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-facets-histogram-facet.html
 * @deprecated Facets are deprecated and will be removed in a future release. You are encouraged to migrate to aggregations instead.
 */
class Histogram extends AbstractFacet
{
    /**
     * Sets the field for histogram.
     *
     * @param string $field The name of the field for the histogram
     *
     * @return $this
     */
    public function setField($field)
    {
        return $this->setParam('field', $field);
    }

    /**
     * Set the value for interval.
     *
     * @param string $interval
     *
     * @return $this
     */
    public function setInterval($interval)
    {
        return $this->setParam('interval', $interval);
    }

    /**
     * Set the fields for key_field and value_field.
     *
     * @param string $keyField   Key field
     * @param string $valueField Value field
     *
     * @return $this
     */
    public function setKeyValueFields($keyField, $valueField)
    {
        return $this->setParam('key_field', $keyField)->setParam('value_field', $valueField);
    }

    /**
     * Sets the key and value for this facet by script.
     *
     * @param string $keyScript   Script to check whether it falls into the range.
     * @param string $valueScript Script to use for statistical calculations.
     *
     * @return $this
     */
    public function setKeyValueScripts($keyScript, $valueScript)
    {
        return $this->setParam('key_script', $keyScript)
                    ->setParam('value_script', $valueScript);
    }

    /**
     * Set the "params" essential to the a script.
     *
     * @param array $params Associative array (key/value pair)
     *
     * @return $this
     */
    public function setScriptParams(array $params)
    {
        return $this->setParam('params', $params);
    }

    /**
     * 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 range in the abstract as param.
         */
        $this->_setFacetParam('histogram', $this->_params);

        return parent::toArray();
    }
}