|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Elastica\Aggregation; |
| 4 | + |
| 5 | +/** |
| 6 | + * Class ScriptedMetric |
| 7 | + * @package Elastica\Aggregation |
| 8 | + * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-scripted-metric-aggregation.html |
| 9 | + */ |
| 10 | +class ScriptedMetric extends AbstractAggregation |
| 11 | +{ |
| 12 | + |
| 13 | + /** |
| 14 | + * @param string $name the name if this aggregation |
| 15 | + * @param string|null $initScript Executed prior to any collection of documents |
| 16 | + * @param string|null $mapScript Executed once per document collected |
| 17 | + * @param string|null $combineScript Executed once on each shard after document collection is complete |
| 18 | + * @param string|null $reduceScript Executed once on the coordinating node after all shards have returned their results |
| 19 | + */ |
| 20 | + public function __construct($name, $initScript = null, $mapScript = null, $combineScript = null, $reduceScript = null) |
| 21 | + { |
| 22 | + parent::__construct($name); |
| 23 | + if ($initScript) { |
| 24 | + $this->setInitScript($initScript); |
| 25 | + } |
| 26 | + if ($mapScript) { |
| 27 | + $this->setMapScript($mapScript); |
| 28 | + } |
| 29 | + if ($combineScript) { |
| 30 | + $this->setCombineScript($combineScript); |
| 31 | + } |
| 32 | + if ($reduceScript) { |
| 33 | + $this->setReduceScript($reduceScript); |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * Set the field for this aggregation |
| 39 | + * |
| 40 | + * @param string $script the name of the document field on which to perform this aggregation |
| 41 | + * |
| 42 | + * @return static |
| 43 | + */ |
| 44 | + public function setCombineScript($script) |
| 45 | + { |
| 46 | + return $this->setParam('combine_script', $script); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Set the field for this aggregation |
| 51 | + * |
| 52 | + * @param string $script the name of the document field on which to perform this aggregation |
| 53 | + * |
| 54 | + * @return static |
| 55 | + */ |
| 56 | + public function setInitScript($script) |
| 57 | + { |
| 58 | + return $this->setParam('init_script', $script); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * Set the field for this aggregation |
| 63 | + * |
| 64 | + * @param string $script the name of the document field on which to perform this aggregation |
| 65 | + * |
| 66 | + * @return static |
| 67 | + */ |
| 68 | + public function setMapScript($script) |
| 69 | + { |
| 70 | + return $this->setParam('map_script', $script); |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * Set the field for this aggregation |
| 75 | + * |
| 76 | + * @param string $script the name of the document field on which to perform this aggregation |
| 77 | + * |
| 78 | + * @return static |
| 79 | + */ |
| 80 | + public function setReduceScript($script) |
| 81 | + { |
| 82 | + return $this->setParam('reduce_script', $script); |
| 83 | + } |
| 84 | + |
| 85 | +} |
0 commit comments