1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the ONGR package. |
5
|
|
|
* |
6
|
|
|
* (c) NFQ Technologies UAB <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace ONGR\ElasticsearchBundle\DSL\Aggregation; |
13
|
|
|
|
14
|
|
|
use ONGR\ElasticsearchBundle\DSL\Aggregation\Type\MetricTrait; |
15
|
|
|
use ONGR\ElasticsearchBundle\DSL\ScriptAwareTrait; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class representing Percentile Ranks Aggregation. |
19
|
|
|
*/ |
20
|
|
|
class PercentileRanksAggregation extends AbstractAggregation |
21
|
|
|
{ |
22
|
|
|
use MetricTrait; |
23
|
|
|
use ScriptAwareTrait; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
private $values; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var int |
32
|
|
|
*/ |
33
|
|
|
private $compression; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @return array |
37
|
|
|
*/ |
38
|
|
|
public function getValues() |
39
|
|
|
{ |
40
|
|
|
return $this->values; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param array $values |
45
|
|
|
*/ |
46
|
|
|
public function setValues($values) |
47
|
|
|
{ |
48
|
|
|
$this->values = $values; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return int |
53
|
|
|
*/ |
54
|
|
|
public function getCompression() |
55
|
|
|
{ |
56
|
|
|
return $this->compression; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param int $compression |
61
|
|
|
*/ |
62
|
|
|
public function setCompression($compression) |
63
|
|
|
{ |
64
|
|
|
$this->compression = $compression; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
|
|
public function getType() |
71
|
|
|
{ |
72
|
|
|
return 'percentile_ranks'; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* {@inheritdoc} |
77
|
|
|
*/ |
78
|
|
|
public function getArray() |
79
|
|
|
{ |
80
|
|
|
$out = array_filter( |
81
|
|
|
[ |
82
|
|
|
'field' => $this->getField(), |
83
|
|
|
'script' => $this->getScript(), |
84
|
|
|
'values' => $this->getValues(), |
85
|
|
|
'compression' => $this->getCompression(), |
86
|
|
|
], |
87
|
|
|
function ($val) { |
88
|
|
|
return ($val || is_numeric($val)); |
89
|
|
|
} |
90
|
|
|
); |
91
|
|
|
|
92
|
|
|
$this->isRequiredParametersSet($out); |
93
|
|
|
|
94
|
|
|
return $out; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param array $a |
99
|
|
|
* |
100
|
|
|
* @return bool |
101
|
|
|
* |
102
|
|
|
* @throws \LogicException |
103
|
|
|
*/ |
104
|
|
|
private function isRequiredParametersSet($a) |
105
|
|
|
{ |
106
|
|
|
if (array_key_exists('field', $a) && array_key_exists('values', $a) |
107
|
|
|
|| (array_key_exists('script', $a) && array_key_exists('values', $a)) |
108
|
|
|
) { |
109
|
|
|
return true; |
110
|
|
|
} |
111
|
|
|
throw new \LogicException('Percentile ranks aggregation must have field and values or script and values set.'); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|