From 0977acb0a2c945a92ec27b9faaa2efdeae6f6f97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zigmas=20Satkevi=C4=8Dius?= <zsatkevicius@nfq.lt> Date: Mon, 12 Jan 2015 17:29:49 +0200 Subject: [PATCH] Added cardinality aggregation. Closes #119. --- Aggregation/CardinalityAggregation.php | 95 ++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 Aggregation/CardinalityAggregation.php diff --git a/Aggregation/CardinalityAggregation.php b/Aggregation/CardinalityAggregation.php new file mode 100644 index 0000000..070f77b --- /dev/null +++ b/Aggregation/CardinalityAggregation.php @@ -0,0 +1,95 @@ +<?php + +/* + * This file is part of the ONGR package. + * + * (c) NFQ Technologies UAB <info@nfq.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace ONGR\ElasticsearchBundle\DSL\Aggregation; + +use ONGR\ElasticsearchBundle\DSL\Aggregation\Type\MetricTrait; + +/** + * Difference values counter. + */ +class CardinalityAggregation extends AbstractAggregation +{ + use MetricTrait; + + /** + * @var int + */ + private $precisionThreshold; + + /** + * @var bool + */ + private $rehash; + + /** + * {@inheritdoc} + */ + public function getArray() + { + if (!$this->getField()) { + return new \stdClass(); + } + + $out['field'] = $this->getField(); + if ($this->getPrecisionThreshold()) { + $out['precision_threshold'] = $this->getPrecisionThreshold(); + } + + if ($this->isRehash() !== null) { + $out['rehash'] = $this->isRehash(); + } + + return $out; + } + + /** + * Precision threshold. + * + * @param int $precision Precision Threshold. + */ + public function setPrecisionThreshold($precision) + { + $this->precisionThreshold = $precision; + } + + /** + * @return int + */ + public function getPrecisionThreshold() + { + return $this->precisionThreshold; + } + + /** + * @return bool + */ + public function isRehash() + { + return $this->rehash; + } + + /** + * @param bool $rehash + */ + public function setRehash($rehash) + { + $this->rehash = $rehash; + } + + /** + * {@inheritdoc} + */ + public function getType() + { + return 'cardinality'; + } +} -- GitLab