diff --git a/Aggregation/ChildrenAggregation.php b/Aggregation/ChildrenAggregation.php new file mode 100644 index 0000000000000000000000000000000000000000..28a23aa11c20216ec7ae4e9fe5b3d5c93833c810 --- /dev/null +++ b/Aggregation/ChildrenAggregation.php @@ -0,0 +1,67 @@ +<?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\BucketingTrait; + +/** + * Class representing ChildrenAggregation. + */ +class ChildrenAggregation extends AbstractAggregation +{ + use BucketingTrait; + + /** + * @var string + */ + private $children; + + /** + * Return children. + * + * @return string + */ + public function getChildren() + { + return $this->children; + } + + /** + * Sets children. + * + * @param string $children + */ + public function setChildren($children) + { + $this->children = $children; + } + + /** + * {@inheritdoc} + */ + public function getType() + { + return 'children'; + } + + /** + * {@inheritdoc} + */ + public function getArray() + { + if (count($this->getAggregations()) == 0) { + throw new \LogicException("Children aggregation `{$this->getName()}` has no aggregations added"); + } + + return ['type' => $this->getChildren()]; + } +} diff --git a/Filter/HasChildFilter.php b/Filter/HasChildFilter.php new file mode 100644 index 0000000000000000000000000000000000000000..6af77f1f7b08f5ba7c4675c94a1d1f22892ad250 --- /dev/null +++ b/Filter/HasChildFilter.php @@ -0,0 +1,70 @@ +<?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; + +/** + * Elasticsearch has_child filter. + */ +class HasChildFilter implements BuilderInterface +{ + use ParametersTrait; + + /** + * @var string + */ + private $type; + + /** + * @var string + */ + private $filter; + + /** + * @param string $type + * @param BuilderInterface $filter + * @param array $parameters + */ + public function __construct($type, BuilderInterface $filter, array $parameters = []) + { + $this->type = $type; + $this->filter = $filter; + $this->setParameters($parameters); + } + + /** + * {@inheritdoc} + */ + public function getType() + { + return 'has_child'; + } + + /** + * {@inheritdoc} + */ + public function toArray() + { + $query = [ + 'type' => $this->type, + 'filter' => [ + $this->filter->getType() => $this->filter->toArray(), + ], + ]; + + $output = $this->processArray($query); + + return $output; + } +} diff --git a/Filter/HasParentFilter.php b/Filter/HasParentFilter.php new file mode 100644 index 0000000000000000000000000000000000000000..50ee8e54aeee6d6798da9fcf597f410601626f3c --- /dev/null +++ b/Filter/HasParentFilter.php @@ -0,0 +1,70 @@ +<?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; + +/** + * Elasticsearch has_parent filter. + */ +class HasParentFilter implements BuilderInterface +{ + use ParametersTrait; + + /** + * @var string + */ + private $parentType; + + /** + * @var BuilderInterface + */ + private $filter; + + /** + * @param string $parentType + * @param BuilderInterface $filter + * @param array $parameters + */ + public function __construct($parentType, BuilderInterface $filter, array $parameters = []) + { + $this->parentType = $parentType; + $this->filter = $filter; + $this->setParameters($parameters); + } + + /** + * {@inheritdoc} + */ + public function getType() + { + return 'has_parent'; + } + + /** + * {@inheritdoc} + */ + public function toArray() + { + $query = [ + 'parent_type' => $this->parentType, + 'filter' => [ + $this->filter->getType() => $this->filter->toArray(), + ], + ]; + + $output = $this->processArray($query); + + return $output; + } +} diff --git a/Query/HasChildQuery.php b/Query/HasChildQuery.php new file mode 100644 index 0000000000000000000000000000000000000000..876cedf89a899a6e056e1a57ab58db6715b41e53 --- /dev/null +++ b/Query/HasChildQuery.php @@ -0,0 +1,70 @@ +<?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\Query; + +use ONGR\ElasticsearchBundle\DSL\BuilderInterface; +use ONGR\ElasticsearchBundle\DSL\ParametersTrait; + +/** + * Elasticsearch has_child query class. + */ +class HasChildQuery implements BuilderInterface +{ + use ParametersTrait; + + /** + * @var string + */ + private $type; + + /** + * @var BuilderInterface + */ + private $query; + + /** + * @param string $type + * @param BuilderInterface $query + * @param array $parameters + */ + public function __construct($type, BuilderInterface $query, array $parameters = []) + { + $this->type = $type; + $this->query = $query; + $this->setParameters($parameters); + } + + /** + * {@inheritdoc} + */ + public function getType() + { + return 'has_child'; + } + + /** + * {@inheritdoc} + */ + public function toArray() + { + $query = [ + 'type' => $this->type, + 'query' => [ + $this->query->getType() => $this->query->toArray(), + ], + ]; + + $output = $this->processArray($query); + + return $output; + } +} diff --git a/Query/HasParentQuery.php b/Query/HasParentQuery.php new file mode 100644 index 0000000000000000000000000000000000000000..9303b42494b965fb1b57b32067acc03f3bbaaa22 --- /dev/null +++ b/Query/HasParentQuery.php @@ -0,0 +1,70 @@ +<?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\Query; + +use ONGR\ElasticsearchBundle\DSL\BuilderInterface; +use ONGR\ElasticsearchBundle\DSL\ParametersTrait; + +/** + * Elasticsearch has_parent query class. + */ +class HasParentQuery implements BuilderInterface +{ + use ParametersTrait; + + /** + * @var string + */ + private $parentType; + + /** + * @var BuilderInterface + */ + private $query; + + /** + * @param string $parentType + * @param BuilderInterface $query + * @param array $parameters + */ + public function __construct($parentType, BuilderInterface $query, array $parameters = []) + { + $this->parentType = $parentType; + $this->query = $query; + $this->setParameters($parameters); + } + + /** + * {@inheritdoc} + */ + public function getType() + { + return 'has_parent'; + } + + /** + * {@inheritdoc} + */ + public function toArray() + { + $query = [ + 'parent_type' => $this->parentType, + 'query' => [ + $this->query->getType() => $this->query->toArray(), + ], + ]; + + $output = $this->processArray($query); + + return $output; + } +}