Skip to content
Snippets Groups Projects
Commit 2fb5f4df authored by Mantas's avatar Mantas
Browse files

Merge pull request #193 from juliensantos87/master

Add Parent-Child Query/Filter/Aggregation
parents fc3b1297 9ddfad7c
No related branches found
No related tags found
No related merge requests found
<?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()];
}
}
<?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;
}
}
<?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;
}
}
<?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;
}
}
<?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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment