1 | <?php |
||
23 | * @link http://goo.gl/JbQsI3 |
||
24 | */ |
||
25 | class ScriptedMetricAggregation extends AbstractAggregation |
||
26 | { |
||
27 | use MetricTrait; |
||
28 | |||
29 | public function __construct( |
||
30 | private string $name, |
||
|
|||
31 | private mixed $initScript = null, |
||
32 | private mixed $mapScript = null, |
||
33 | private mixed $combineScript = null, |
||
34 | private mixed $reduceScript = null |
||
35 | ) { |
||
36 | |||
37 | parent::__construct($name); |
||
38 | |||
39 | $this->setInitScript($initScript); |
||
40 | $this->setMapScript($mapScript); |
||
41 | $this->setCombineScript($combineScript); |
||
42 | $this->setReduceScript($reduceScript); |
||
43 | } |
||
44 | |||
45 | public function getType(): string |
||
46 | { |
||
47 | return 'scripted_metric'; |
||
48 | } |
||
49 | |||
50 | public function getInitScript(): mixed |
||
51 | { |
||
52 | return $this->initScript; |
||
53 | } |
||
54 | |||
55 | public function setInitScript(mixed $initScript): static |
||
56 | { |
||
57 | $this->initScript = $initScript; |
||
58 | |||
59 | return $this; |
||
60 | } |
||
61 | |||
62 | public function getMapScript(): mixed |
||
63 | { |
||
64 | return $this->mapScript; |
||
65 | } |
||
66 | |||
67 | public function setMapScript(mixed $mapScript): static |
||
68 | { |
||
69 | $this->mapScript = $mapScript; |
||
70 | |||
71 | return $this; |
||
72 | } |
||
73 | |||
74 | public function getCombineScript(): mixed |
||
75 | { |
||
76 | return $this->combineScript; |
||
77 | } |
||
78 | |||
79 | public function setCombineScript(mixed $combineScript): static |
||
80 | { |
||
81 | $this->combineScript = $combineScript; |
||
82 | |||
83 | return $this; |
||
84 | } |
||
85 | |||
86 | public function getReduceScript(): mixed |
||
87 | { |
||
88 | return $this->reduceScript; |
||
89 | } |
||
90 | |||
91 | public function setReduceScript(mixed $reduceScript): static |
||
92 | { |
||
93 | $this->reduceScript = $reduceScript; |
||
94 | |||
95 | return $this; |
||
96 | } |
||
97 | |||
98 | |||
99 | public function getArray(): array |
||
100 | { |
||
101 | return array_filter( |
||
102 | [ |
||
103 | 'init_script' => $this->getInitScript(), |
||
104 | 'map_script' => $this->getMapScript(), |
||
105 | 'combine_script' => $this->getCombineScript(), |
||
106 | 'reduce_script' => $this->getReduceScript(), |
||
107 | ] |
||
108 | ); |
||
109 | } |
||
110 | } |
||
111 |