Completed
Push — master ( 220b9d...1f094b )
by Nicolas
02:00
created

Percentiles::setKeyed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
namespace Elastica\Aggregation;
3
4
/**
5
 * Class Percentiles.
6
 *
7
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-percentile-aggregation.html
8
 */
9
class Percentiles extends AbstractSimpleAggregation
10
{
11
    /**
12
     * @param string $name  the name of this aggregation
13
     * @param string $field the field on which to perform this aggregation
14
     */
15
    public function __construct($name, $field = null)
16
    {
17
        parent::__construct($name);
18
19
        if (!is_null($field)) {
20
            $this->setField($field);
21
        }
22
    }
23
24
    /**
25
     * Set compression parameter.
26
     *
27
     * @param float $value
28
     *
29
     * @return Percentiles $this
30
     */
31
    public function setCompression(float $value): Percentiles
32
    {
33
        $compression = array('compression' => $value);
34
        return $this->setParam('tdigest', $compression);
35
    }
36
37
    /**
38
     * Set hdr parameter.
39
     *
40
     * @param string $key
41
     * @param float $value
42
     *
43
     * @return Percentiles $this
44
     */
45
    public function setHdr(string $key, float $value): Percentiles
46
    {
47
        $compression = array($key => $value);
48
        return $this->setParam('hdr', $compression);
49
    }
50
51
    /**
52
     * the keyed flag is set to true which associates a unique string
53
     * key with each bucket and returns the ranges as a hash
54
     * rather than an array
55
     *
56
     * @param bool $keyed
57
     *
58
     * @return Percentiles $this
59
     */
60
    public function setKeyed(bool $keyed = true): Percentiles
61
    {
62
        return $this->setParam('keyed', $keyed);
63
    }
64
65
    /**
66
     * Set which percents must be returned.
67
     *
68
     * @param float[] $percents
69
     *
70
     * @return Percentiles $this
71
     */
72
    public function setPercents(array $percents): Percentiles
73
    {
74
        return $this->setParam('percents', $percents);
75
    }
76
77
    /**
78
     * Add yet another percent to result.
79
     *
80
     * @param float $percent
81
     *
82
     * @return Percentiles $this
83
     */
84
    public function addPercent(float $percent): Percentiles
85
    {
86
        return $this->addParam('percents', $percent);
87
    }
88
89
    /**
90
     * Defines how documents that are missing a value should
91
     * be treated
92
     *
93
     * @param float $missing
94
     *
95
     * @return Percentiles
96
     */
97
    public function setMissing(float $missing): Percentiles
98
    {
99
        return $this->setParam('missing', $missing);
100
    }
101
}
102