Skip to content

Commit 06c553b

Browse files
committed
Merge branch 'OliverSkroblin-master' into 6.x
# Conflicts: # src/FieldAwareTrait.php # src/Sort/NestedSort.php
2 parents e0273b1 + cfa3b38 commit 06c553b

File tree

3 files changed

+98
-4
lines changed

3 files changed

+98
-4
lines changed

src/Aggregation/Bucketing/CompositeAggregation.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class CompositeAggregation extends AbstractAggregation
4343
* Inner aggregations container init.
4444
*
4545
* @param string $name
46-
* @param BuilderInterface[] $sources
46+
* @param AbstractAggregation[] $sources
4747
*/
4848
public function __construct($name, $sources = [])
4949
{
@@ -55,16 +55,20 @@ public function __construct($name, $sources = [])
5555
}
5656

5757
/**
58-
* @param BuilderInterface $agg
58+
* @param AbstractAggregation $agg
5959
*
6060
* @throws \LogicException
6161
*
6262
* @return self
6363
*/
64-
public function addSource(BuilderInterface $agg)
64+
public function addSource(AbstractAggregation $agg)
6565
{
66+
$array = $agg->getArray();
67+
68+
$array = is_array($array) ? array_merge($array, $agg->getParameters()) : $array;
69+
6670
$this->sources[] = [
67-
$agg->getName() => [ $agg->getType() => $agg->getArray() ]
71+
$agg->getName() => [ $agg->getType() => $array ]
6872
];
6973

7074
return $this;

src/Search.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,24 @@ public function setTrackTotalHits(bool $trackTotalHits)
481481
return $this;
482482
}
483483

484+
/**
485+
* @return bool
486+
*/
487+
public function isTrackTotalHits()
488+
{
489+
return $this->trackTotalHits;
490+
}
491+
492+
/**
493+
* @param bool $trackTotalHits
494+
* @return $this
495+
*/
496+
public function setTrackTotalHits(bool $trackTotalHits)
497+
{
498+
$this->trackTotalHits = $trackTotalHits;
499+
return $this;
500+
}
501+
484502
/**
485503
* @return int
486504
*/

tests/Unit/Aggregation/Bucketing/CompositeAggregationTest.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,76 @@ public function testGetType()
9595
$result = $aggregation->getType();
9696
$this->assertEquals('composite', $result);
9797
}
98+
99+
public function testTermsSourceWithOrderParameter()
100+
{
101+
$compositeAgg = new CompositeAggregation('composite_with_order');
102+
$termsAgg = new TermsAggregation('test_term_agg', 'test_field');
103+
$termsAgg->addParameter('order', 'asc');
104+
$compositeAgg->addSource($termsAgg);
105+
106+
$expectedResult = [
107+
'composite' => [
108+
'sources' => [
109+
[
110+
'test_term_agg' => [ 'terms' => ['field' => 'test_field', 'order' => 'asc'] ],
111+
]
112+
]
113+
],
114+
];
115+
116+
$this->assertEquals($expectedResult, $compositeAgg->toArray());
117+
}
118+
119+
120+
public function testTermsSourceWithDescOrderParameter()
121+
{
122+
$compositeAgg = new CompositeAggregation('composite_with_order');
123+
$termsAgg = new TermsAggregation('test_term_agg', 'test_field');
124+
$termsAgg->addParameter('order', 'desc');
125+
$compositeAgg->addSource($termsAgg);
126+
127+
$expectedResult = [
128+
'composite' => [
129+
'sources' => [
130+
[
131+
'test_term_agg' => [ 'terms' => ['field' => 'test_field', 'order' => 'desc'] ],
132+
]
133+
]
134+
],
135+
];
136+
137+
$this->assertEquals($expectedResult, $compositeAgg->toArray());
138+
}
139+
140+
141+
public function testMultipleSourcesWithDifferentOrders()
142+
{
143+
$compositeAgg = new CompositeAggregation('composite_with_order');
144+
145+
$termsAgg = new TermsAggregation('test_term_agg_1', 'test_field');
146+
$termsAgg->addParameter('order', 'desc');
147+
$compositeAgg->addSource($termsAgg);
148+
149+
$termsAgg = new TermsAggregation('test_term_agg_2', 'test_field');
150+
$termsAgg->addParameter('order', 'asc');
151+
$compositeAgg->addSource($termsAgg);
152+
153+
$expectedResult = [
154+
'composite' => [
155+
'sources' => [
156+
[
157+
'test_term_agg_1' => [ 'terms' => ['field' => 'test_field', 'order' => 'desc'] ],
158+
],
159+
[
160+
'test_term_agg_2' => [ 'terms' => ['field' => 'test_field', 'order' => 'asc'] ],
161+
]
162+
]
163+
],
164+
];
165+
166+
$this->assertEquals($expectedResult, $compositeAgg->toArray());
167+
}
168+
169+
98170
}

0 commit comments

Comments
 (0)