Completed
Pull Request — master (#1876)
by romain
02:29
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
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 KeyedTrait;
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
     * Set which percents must be returned.
53
     *
54
     * @param float[] $percents
55
     *
56
     * @return $this
57
     */
58
    public function setPercents(array $percents): self
59
    {
60
        return $this->setParam('percents', $percents);
61
    }
62
63
    /**
64
     * Add yet another percent to result.
65
     *
66
     * @return $this
67
     */
68
    public function addPercent(float $percent): self
69
    {
70
        return $this->addParam('percents', $percent);
71
    }
72
73
    /**
74
     * Defines how documents that are missing a value should
75
     * be treated.
76
     *
77
     * @return $this
78
     */
79
    public function setMissing(float $missing): self
80
    {
81
        return $this->setParam('missing', $missing);
82
    }
83
}
84