summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/lib/Elastica/Aggregation/Filters.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/ruflin/elastica/lib/Elastica/Aggregation/Filters.php')
-rw-r--r--vendor/ruflin/elastica/lib/Elastica/Aggregation/Filters.php59
1 files changed, 59 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/lib/Elastica/Aggregation/Filters.php b/vendor/ruflin/elastica/lib/Elastica/Aggregation/Filters.php
new file mode 100644
index 00000000..e0fbf060
--- /dev/null
+++ b/vendor/ruflin/elastica/lib/Elastica/Aggregation/Filters.php
@@ -0,0 +1,59 @@
+<?php
+namespace Elastica\Aggregation;
+
+use Elastica\Filter\AbstractFilter;
+
+/**
+ * Class Filters.
+ *
+ * @link http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filters-aggregation.html
+ */
+class Filters extends AbstractAggregation
+{
+ /**
+ * Add a filter.
+ *
+ * If a name is given, it will be added as a key, otherwise considered as an anonymous filter
+ *
+ * @param AbstractFilter $filter
+ * @param string $name
+ *
+ * @return $this
+ */
+ public function addFilter(AbstractFilter $filter, $name = '')
+ {
+ if (empty($name)) {
+ $filterArray[] = $filter->toArray();
+ } else {
+ $filterArray[$name] = $filter->toArray();
+ }
+
+ return $this->addParam('filters', $filterArray);
+ }
+
+ /**
+ * @return array
+ */
+ public function toArray()
+ {
+ $array = array();
+ $filters = $this->getParam('filters');
+
+ foreach ($filters as $filter) {
+ // Detect between anonymous filters and named ones
+ $key = key($filter);
+
+ if (is_string($key)) {
+ $array['filters']['filters'][$key] = current($filter);
+ } else {
+ $array['filters']['filters'][] = current($filter);
+ }
+ }
+
+ if ($this->_aggs) {
+ $array['aggs'] = $this->_aggs;
+ }
+
+ return $array;
+ }
+}