diff --git a/Filter/NestedFilter.php b/Filter/NestedFilter.php new file mode 100644 index 0000000000000000000000000000000000000000..bba9a9748e5373f8aebb14fca25200c2dc06b92c --- /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; + } +}