Skip to content
Snippets Groups Projects
Unverified Commit 06c553b0 authored by Simonas Šerlinskas's avatar Simonas Šerlinskas
Browse files

Merge branch 'OliverSkroblin-master' into 6.x

# Conflicts:
#	src/FieldAwareTrait.php
#	src/Sort/NestedSort.php
parents e0273b1f cfa3b38e
No related branches found
No related tags found
No related merge requests found
......@@ -43,7 +43,7 @@ class CompositeAggregation extends AbstractAggregation
* Inner aggregations container init.
*
* @param string $name
* @param BuilderInterface[] $sources
* @param AbstractAggregation[] $sources
*/
public function __construct($name, $sources = [])
{
......@@ -55,16 +55,20 @@ class CompositeAggregation extends AbstractAggregation
}
/**
* @param BuilderInterface $agg
* @param AbstractAggregation $agg
*
* @throws \LogicException
*
* @return self
*/
public function addSource(BuilderInterface $agg)
public function addSource(AbstractAggregation $agg)
{
$array = $agg->getArray();
$array = is_array($array) ? array_merge($array, $agg->getParameters()) : $array;
$this->sources[] = [
$agg->getName() => [ $agg->getType() => $agg->getArray() ]
$agg->getName() => [ $agg->getType() => $array ]
];
return $this;
......
......@@ -481,6 +481,24 @@ class Search
return $this;
}
/**
* @return bool
*/
public function isTrackTotalHits()
{
return $this->trackTotalHits;
}
/**
* @param bool $trackTotalHits
* @return $this
*/
public function setTrackTotalHits(bool $trackTotalHits)
{
$this->trackTotalHits = $trackTotalHits;
return $this;
}
/**
* @return int
*/
......
......@@ -95,4 +95,76 @@ class CompositeAggregationTest extends \PHPUnit\Framework\TestCase
$result = $aggregation->getType();
$this->assertEquals('composite', $result);
}
public function testTermsSourceWithOrderParameter()
{
$compositeAgg = new CompositeAggregation('composite_with_order');
$termsAgg = new TermsAggregation('test_term_agg', 'test_field');
$termsAgg->addParameter('order', 'asc');
$compositeAgg->addSource($termsAgg);
$expectedResult = [
'composite' => [
'sources' => [
[
'test_term_agg' => [ 'terms' => ['field' => 'test_field', 'order' => 'asc'] ],
]
]
],
];
$this->assertEquals($expectedResult, $compositeAgg->toArray());
}
public function testTermsSourceWithDescOrderParameter()
{
$compositeAgg = new CompositeAggregation('composite_with_order');
$termsAgg = new TermsAggregation('test_term_agg', 'test_field');
$termsAgg->addParameter('order', 'desc');
$compositeAgg->addSource($termsAgg);
$expectedResult = [
'composite' => [
'sources' => [
[
'test_term_agg' => [ 'terms' => ['field' => 'test_field', 'order' => 'desc'] ],
]
]
],
];
$this->assertEquals($expectedResult, $compositeAgg->toArray());
}
public function testMultipleSourcesWithDifferentOrders()
{
$compositeAgg = new CompositeAggregation('composite_with_order');
$termsAgg = new TermsAggregation('test_term_agg_1', 'test_field');
$termsAgg->addParameter('order', 'desc');
$compositeAgg->addSource($termsAgg);
$termsAgg = new TermsAggregation('test_term_agg_2', 'test_field');
$termsAgg->addParameter('order', 'asc');
$compositeAgg->addSource($termsAgg);
$expectedResult = [
'composite' => [
'sources' => [
[
'test_term_agg_1' => [ 'terms' => ['field' => 'test_field', 'order' => 'desc'] ],
],
[
'test_term_agg_2' => [ 'terms' => ['field' => 'test_field', 'order' => 'asc'] ],
]
]
],
];
$this->assertEquals($expectedResult, $compositeAgg->toArray());
}
}
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