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\ElasticsearchDSL\Aggregation\Metric; |
13
|
|
|
|
14
|
|
|
use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation; |
15
|
|
|
use ONGR\ElasticsearchDSL\Aggregation\Type\MetricTrait; |
16
|
|
|
use ONGR\ElasticsearchDSL\ScriptAwareTrait; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class representing StatsAggregation. |
20
|
|
|
* |
21
|
|
|
* @link http://goo.gl/JbQsI3 |
22
|
|
|
*/ |
23
|
|
|
class ScriptedMetricAggregation extends AbstractAggregation |
24
|
|
|
{ |
25
|
|
|
use MetricTrait; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var mixed |
29
|
|
|
*/ |
30
|
|
|
private $initScript; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var mixed |
34
|
|
|
*/ |
35
|
|
|
private $mapScript; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var mixed |
39
|
|
|
*/ |
40
|
|
|
private $combineScript; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var mixed |
44
|
|
|
*/ |
45
|
|
|
private $reduceScript; |
46
|
|
|
/** |
47
|
|
|
* ScriptedMetricAggregation constructor. |
48
|
|
|
* @param string $name |
49
|
|
|
* @param mixed $initScript |
50
|
|
|
* @param mixed $mapScript |
51
|
|
|
* @param mixed $combineScript |
52
|
|
|
* @param mixed $reduceScript |
53
|
|
|
*/ |
54
|
|
|
public function __construct( |
55
|
|
|
$name, |
56
|
|
|
$initScript = null, |
57
|
|
|
$mapScript = null, |
58
|
|
|
$combineScript = null, |
59
|
|
|
$reduceScript = null |
60
|
|
|
) { |
61
|
|
|
|
62
|
|
|
parent::__construct($name); |
63
|
|
|
|
64
|
|
|
$this->setInitScript($initScript); |
65
|
|
|
$this->setMapScript($mapScript); |
66
|
|
|
$this->setCombineScript($combineScript); |
67
|
|
|
$this->setReduceScript($reduceScript); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* {@inheritdoc} |
72
|
|
|
*/ |
73
|
|
|
public function getType() |
74
|
|
|
{ |
75
|
|
|
return 'stats'; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return mixed |
80
|
|
|
*/ |
81
|
|
|
public function getInitScript() |
82
|
|
|
{ |
83
|
|
|
return $this->initScript; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param mixed $initScript |
88
|
|
|
*/ |
89
|
|
|
public function setInitScript($initScript) |
90
|
|
|
{ |
91
|
|
|
$this->initScript = $initScript; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return mixed |
96
|
|
|
*/ |
97
|
|
|
public function getMapScript() |
98
|
|
|
{ |
99
|
|
|
return $this->mapScript; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param mixed $mapScript |
104
|
|
|
*/ |
105
|
|
|
public function setMapScript($mapScript) |
106
|
|
|
{ |
107
|
|
|
$this->mapScript = $mapScript; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return mixed |
112
|
|
|
*/ |
113
|
|
|
public function getCombineScript() |
114
|
|
|
{ |
115
|
|
|
return $this->combineScript; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param mixed $combineScript |
120
|
|
|
*/ |
121
|
|
|
public function setCombineScript($combineScript) |
122
|
|
|
{ |
123
|
|
|
$this->combineScript = $combineScript; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return mixed |
128
|
|
|
*/ |
129
|
|
|
public function getReduceScript() |
130
|
|
|
{ |
131
|
|
|
return $this->reduceScript; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param mixed $reduceScript |
136
|
|
|
*/ |
137
|
|
|
public function setReduceScript($reduceScript) |
138
|
|
|
{ |
139
|
|
|
$this->reduceScript = $reduceScript; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* {@inheritdoc} |
144
|
|
|
*/ |
145
|
|
|
public function getArray() |
146
|
|
|
{ |
147
|
|
|
$out = array_filter( |
148
|
|
|
[ |
149
|
|
|
'init_script' => $this->getInitScript(), |
150
|
|
|
'map_script' => $this->getMapScript(), |
151
|
|
|
'combine_script' => $this->getCombineScript(), |
152
|
|
|
'reduce_script' => $this->getReduceScript(), |
153
|
|
|
] |
154
|
|
|
); |
155
|
|
|
|
156
|
|
|
return $out; |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|