Skip to content
Snippets Groups Projects
Commit db57301d authored by Bohuslav Simek's avatar Bohuslav Simek Committed by Simonas Šerlinskas
Browse files

Add suport for size and after property into composite aggregation

parent 2e2d7efa
No related branches found
No related tags found
No related merge requests found
......@@ -29,6 +29,16 @@ class CompositeAggregation extends AbstractAggregation
*/
private $sources = [];
/**
* @var int
*/
private $size;
/**
* @var array
*/
private $after;
/**
* Inner aggregations container init.
*
......@@ -65,9 +75,19 @@ class CompositeAggregation extends AbstractAggregation
*/
public function getArray()
{
return [
$array = [
'sources' => $this->sources,
];
if ($this->size !== null) {
$array['size'] = $this->size;
}
if (!empty($this->after)) {
$array['after'] = $this->after;
}
return $array;
}
/**
......@@ -77,4 +97,48 @@ class CompositeAggregation extends AbstractAggregation
{
return 'composite';
}
/**
* Sets size
*
* @param int $size Size
*
* @return void
*/
public function setSize($size)
{
$this->size = $size;
}
/**
* Returns size
*
* @return int
*/
public function getSize()
{
return $this->size;
}
/**
* Sets after
*
* @param array $after After
*
* @return void
*/
public function setAfter(array $after)
{
$this->after = $after;
}
/**
* Returns after
*
* @return array
*/
public function getAfter()
{
return $this->after;
}
}
......@@ -38,6 +38,54 @@ class CompositeAggregationTest extends \PHPUnit\Framework\TestCase
$this->assertEquals($expectedResult, $compositeAgg->toArray());
}
/**
* Test for composite aggregation toArray() method with size and after part.
*/
public function testToArrayWithSizeAndAfter()
{
$compositeAgg = new CompositeAggregation('composite_test_agg');
$termsAgg = new TermsAggregation('test_term_agg', 'test_field');
$compositeAgg->addSource($termsAgg);
$compositeAgg->setSize(5);
$compositeAgg->setAfter(['test_term_agg' => 'test']);
$expectedResult = [
'composite' => [
'sources' => [
[
'test_term_agg' => [ 'terms' => ['field' => 'test_field'] ],
]
],
'size' => 5,
'after' => ['test_term_agg' => 'test']
],
];
$this->assertEquals($expectedResult, $compositeAgg->toArray());
}
/**
* Test for composite aggregation getSize() method.
*/
public function testGetSize()
{
$compositeAgg = new CompositeAggregation('composite_test_agg');
$compositeAgg->setSize(5);
$this->assertEquals(5, $compositeAgg->getSize());
}
/**
* Test for composite aggregation getAfter() method.
*/
public function testGetAfter()
{
$compositeAgg = new CompositeAggregation('composite_test_agg');
$compositeAgg->setAfter(['test_term_agg' => 'test']);
$this->assertEquals(['test_term_agg' => 'test'], $compositeAgg->getAfter());
}
/**
* Tests getType method.
*/
......
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