From 4b2cab9e34a12cd230f62bcd4d15d5afae7044f2 Mon Sep 17 00:00:00 2001
From: Linas Mockus <linas.mockus@ongr.io>
Date: Mon, 23 Feb 2015 09:51:29 +0200
Subject: [PATCH] Added NestedFilter.

---
 Filter/NestedFilter.php | 75 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)
 create mode 100644 Filter/NestedFilter.php

diff --git a/Filter/NestedFilter.php b/Filter/NestedFilter.php
new file mode 100644
index 0000000..bba9a97
--- /dev/null
+++ b/Filter/NestedFilter.php
@@ -0,0 +1,75 @@
+<?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\Filter;
+
+use ONGR\ElasticsearchBundle\DSL\BuilderInterface;
+use ONGR\ElasticsearchBundle\DSL\ParametersTrait;
+
+/**
+ * Nested filter implementation.
+ */
+class NestedFilter implements BuilderInterface
+{
+    use ParametersTrait;
+
+    /**
+     * @var string
+     */
+    private $path;
+
+    /**
+     * @var BuilderInterface
+     */
+    private $query;
+
+    /**
+     * @var array
+     */
+    private $parameters;
+
+    /**
+     * @param string           $path
+     * @param BuilderInterface $query
+     * @param array            $parameters
+     */
+    public function __construct($path, BuilderInterface $query, array $parameters = [])
+    {
+        $this->path = $path;
+        $this->query = $query;
+        $this->parameters = $parameters;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getType()
+    {
+        return 'nested';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function toArray()
+    {
+        $query = [
+            'path' => $this->path,
+            'filter' => [
+                $this->query->getType() => $this->query->toArray(),
+            ],
+        ];
+
+        $output = $this->processArray($query);
+
+        return $output;
+    }
+}
-- 
GitLab