Skip to content

Commit 12164bc

Browse files
Merge pull request #358 from Flowpack/task/only-apply-size-if-set
TASK: Only apply the size parameter if set
2 parents 301154e + 22d723c commit 12164bc

3 files changed

Lines changed: 11 additions & 9 deletions

File tree

Classes/Eel/ElasticSearchQueryBuilder.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,19 +407,22 @@ public function queryFilterMultiple(array $data, $clauseType = 'must'): ElasticS
407407
* @param string $field The field to aggregate by
408408
* @param string $type Aggregation type
409409
* @param string $parentPath
410-
* @param int $size The amount of buckets to return
410+
* @param int|null $size The amount of buckets to return or null if not applicable to the aggregation
411411
* @return ElasticSearchQueryBuilder
412412
* @throws QueryBuildingException
413413
*/
414-
public function fieldBasedAggregation(string $name, string $field, string $type = 'terms', string $parentPath = '', int $size = 10): ElasticSearchQueryBuilder
414+
public function fieldBasedAggregation(string $name, string $field, string $type = 'terms', string $parentPath = '', ?int $size = null): ElasticSearchQueryBuilder
415415
{
416416
$aggregationDefinition = [
417417
$type => [
418-
'field' => $field,
419-
'size' => $size
418+
'field' => $field
420419
]
421420
];
422421

422+
if ($size !== null) {
423+
$aggregationDefinition[$type]['size'] = $size;
424+
}
425+
423426
$this->aggregation($name, $aggregationDefinition, $parentPath);
424427

425428
return $this;

Tests/Functional/Eel/ElasticSearchQueryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ public function limitImpactGetAccessibleCount(): void
162162

163163
/**
164164
* @test
165+
* @throws QueryBuildingException
165166
*/
166167
public function fieldBasedAggregations(): void
167168
{
@@ -173,7 +174,6 @@ public function fieldBasedAggregations(): void
173174
->getAggregations();
174175

175176
static::assertArrayHasKey($aggregationTitle, $result);
176-
177177
static::assertCount(3, $result[$aggregationTitle]['buckets']);
178178

179179
$expectedChickenBucket = [

Tests/Unit/Eel/ElasticSearchQueryBuilderTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,30 +331,29 @@ public function anSimpleAggregationCanBeAddedToTheRequest(string $type, string $
331331

332332
/**
333333
* @test
334+
* @throws QueryBuildingException
334335
*/
335336
public function anAggregationCanBeSubbedUnderAPath(): void
336337
{
337338
$this->queryBuilder->fieldBasedAggregation('foo', 'bar');
338-
$this->queryBuilder->fieldBasedAggregation('bar', 'bar', 'terms', 'foo');
339+
$this->queryBuilder->fieldBasedAggregation('bar', 'bar', 'terms', 'foo', 22);
339340
$this->queryBuilder->fieldBasedAggregation('baz', 'bar', 'terms', 'foo.bar');
340341

341342
$expected = [
342343
'foo' => [
343344
'terms' => [
344345
'field' => 'bar',
345-
'size' => 10
346346
],
347347
'aggregations' => [
348348
'bar' => [
349349
'terms' => [
350350
'field' => 'bar',
351-
'size' => 10
351+
'size' => 22
352352
],
353353
'aggregations' => [
354354
'baz' => [
355355
'terms' => [
356356
'field' => 'bar',
357-
'size' => 10
358357
],
359358
]
360359
]

0 commit comments

Comments
 (0)