Completed
Pull Request — master (#1875)
by romain
02:37
created

Percentiles::setMissing()   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
3
namespace Elastica\Aggregation;
4
5
/**
6
 * Class Percentiles.
7
 *
8
 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-percentile-aggregation.html
9
 */
10
class Percentiles extends AbstractSimpleAggregation
11
{
12
    use MissingTrait;
13
14
    /**
15
     * @param string $name  the name of this aggregation
16
     * @param string $field the field on which to perform this aggregation
17
     */
18
    public function __construct(string $name, ?string $field = null)
19
    {
20
        parent::__construct($name);
21
22
        if (null !== $field) {
23
            $this->setField($field);
24
        }
25
    }
26
27
    /**
28
     * Set compression parameter.
29
     *
30
     * @return $this
31
     */
32
    public function setCompression(float $value): self
33
    {
34
        $compression = ['compression' => $value];
35
36
        return $this->setParam('tdigest', $compression);
37
    }
38
39
    /**
40
     * Set hdr parameter.
41
     *
42
     * @return $this
43
     */
44
    public function setHdr(string $key, float $value): self
45
    {
46
        $compression = [$key => $value];
47
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
     * @return $this
57
     */
58
    public function setKeyed(bool $keyed = true): self
59
    {
60
        return $this->setParam('keyed', $keyed);
61
    }
62
63
    /**
64
     * Set which percents must be returned.
65
     *
66
     * @param float[] $percents
67
     *
68
     * @return $this
69
     */
70
    public function setPercents(array $percents): self
71
    {
72
        return $this->setParam('percents', $percents);
73
    }
74
75
    /**
76
     * Add yet another percent to result.
77
     *
78
     * @return $this
79
     */
80
    public function addPercent(float $percent): self
81
    {
82
        return $this->addParam('percents', $percent);
83
    }
84
}
85