Skip to content

Commit 9620f5a

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-92128' into 2.3-develop-pr22
2 parents 697db6f + bc3c5db commit 9620f5a

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

app/code/Magento/Elasticsearch/SearchAdapter/Query/Builder/Aggregation.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
*/
1616
class Aggregation
1717
{
18+
/**
19+
* Max number of results returned per single term bucket, i.e. limit of options for layered navigation filter.
20+
* Default ElasticSearch limit is 10
21+
*
22+
* @var int
23+
*/
24+
private static $maxTermBacketSize = 500;
25+
1826
/**
1927
* @var FieldMapperInterface
2028
* @since 100.1.0
@@ -67,6 +75,7 @@ protected function buildBucket(
6775
$searchQuery['body']['aggregations'][$bucket->getName()]= [
6876
'terms' => [
6977
'field' => $field,
78+
'size' => self::$maxTermBacketSize,
7079
],
7180
];
7281
break;

app/code/Magento/Elasticsearch/Test/Unit/SearchAdapter/Query/Builder/AggregationTest.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Elasticsearch\Test\Unit\SearchAdapter\Query\Builder;
77

88
use Magento\Elasticsearch\SearchAdapter\Query\Builder\Aggregation;
9+
use Magento\Framework\Search\Request\BucketInterface;
910
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1011

1112
class AggregationTest extends \PHPUnit\Framework\TestCase
@@ -26,7 +27,7 @@ class AggregationTest extends \PHPUnit\Framework\TestCase
2627
protected $requestInterface;
2728

2829
/**
29-
* @var \Magento\Framework\Search\Request\BucketInterface|\PHPUnit_Framework_MockObject_MockObject
30+
* @var BucketInterface|\PHPUnit_Framework_MockObject_MockObject
3031
*/
3132
protected $requestBucketInterface;
3233

@@ -47,7 +48,7 @@ protected function setUp()
4748
->disableOriginalConstructor()
4849
->getMock();
4950

50-
$this->requestBucketInterface = $this->getMockBuilder(\Magento\Framework\Search\Request\BucketInterface::class)
51+
$this->requestBucketInterface = $this->getMockBuilder(BucketInterface::class)
5152
->disableOriginalConstructor()
5253
->getMock();
5354

@@ -139,28 +140,35 @@ public function testBuildTerm()
139140
'type' => 'product',
140141
'body' => [],
141142
];
143+
$bucketName = 'price_bucket';
142144

143-
$this->requestInterface->expects($this->any())
145+
$this->requestInterface
144146
->method('getAggregation')
145147
->willReturn([$this->requestBucketInterface]);
146148

147-
$this->fieldMapper->expects($this->any())
149+
$this->fieldMapper
148150
->method('getFieldName')
149151
->willReturn('price');
150152

151-
$this->requestBucketInterface->expects($this->any())
153+
$this->requestBucketInterface
152154
->method('getField')
153155
->willReturn('price');
154156

155-
$this->requestBucketInterface->expects($this->any())
157+
$this->requestBucketInterface
156158
->method('getType')
157-
->willReturn('termBucket');
159+
->willReturn(BucketInterface::TYPE_TERM);
158160

159-
$this->requestBucketInterface->expects($this->any())
161+
$this->requestBucketInterface
160162
->method('getName')
161-
->willReturn('price_bucket');
163+
->willReturn($bucketName);
162164

163165
$result = $this->model->build($this->requestInterface, $query);
166+
164167
$this->assertNotNull($result);
168+
$this->assertTrue(
169+
isset($result['body']['aggregations'][$bucketName]['terms']['size']),
170+
'The size have to be specified since by default, ' .
171+
'the terms aggregation will return only the buckets for the top ten terms ordered by the doc_count'
172+
);
165173
}
166174
}

0 commit comments

Comments
 (0)