Skip to content

Commit b947332

Browse files
authored
Merge pull request #3150 from rbayet/fix-deprecated-aggs-name-sort-order
Fixes #3148 Replacing _term agg sort order by _key
2 parents 97efd19 + e0e74f0 commit b947332

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

src/module-elasticsuite-catalog/Model/Attribute/Source/FilterSortOrder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function toOptionArray()
3535
return [
3636
['value' => BucketInterface::SORT_ORDER_COUNT, 'label' => __('Result count')],
3737
['value' => BucketInterface::SORT_ORDER_MANUAL, 'label' => __('Admin sort')],
38-
['value' => BucketInterface::SORT_ORDER_TERM, 'label' => __('Name')],
38+
['value' => BucketInterface::SORT_ORDER_TERM_DEPRECATED, 'label' => __('Name')],
3939
['value' => BucketInterface::SORT_ORDER_RELEVANCE, 'label' => __('Relevance')],
4040
];
4141
}

src/module-elasticsuite-core/Search/Adapter/Elasticsuite/Request/Aggregation/Builder/Term.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function buildBucket(BucketInterface $bucket)
4848
$aggregation['terms']['order'] = $bucket->getSortOrder();
4949
} elseif (in_array($bucket->getSortOrder(), [$bucket::SORT_ORDER_COUNT, $bucket::SORT_ORDER_MANUAL])) {
5050
$aggregation['terms']['order'] = [$bucket::SORT_ORDER_COUNT => SortOrderInterface::SORT_DESC];
51-
} elseif ($bucket->getSortOrder() == $bucket::SORT_ORDER_TERM) {
51+
} elseif (in_array($bucket->getSortOrder(), [$bucket::SORT_ORDER_TERM, $bucket::SORT_ORDER_TERM_DEPRECATED])) {
5252
$aggregation['terms']['order'] = [$bucket::SORT_ORDER_TERM => SortOrderInterface::SORT_ASC];
5353
} elseif ($bucket->getSortOrder() == $bucket::SORT_ORDER_RELEVANCE && !$bucket->isNested()) {
5454
$aggregation['aggregations']['termRelevance'] = ['avg' => ['script' => $bucket::SORT_ORDER_RELEVANCE]];

src/module-elasticsuite-core/Search/Request/BucketInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ interface BucketInterface extends \Magento\Framework\Search\Request\BucketInterf
3535
const TYPE_METRIC = 'metricBucket';
3636

3737
const SORT_ORDER_COUNT = '_count';
38-
const SORT_ORDER_TERM = '_term';
38+
const SORT_ORDER_TERM = '_key';
3939
const SORT_ORDER_RELEVANCE = "_score";
4040
const SORT_ORDER_MANUAL = "_manual";
41+
const SORT_ORDER_TERM_DEPRECATED = '_term';
4142

4243
/**
4344
* @var integer

src/module-elasticsuite-core/Test/Unit/Search/Adapter/Elasticsuite/Request/Aggregation/Builder/TermTest.php

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,46 @@ public function testBasicTermAggregationBuild()
5353
public function testAplhabeticSortOrderTermAggregationBuild()
5454
{
5555
$aggBuilder = $this->getAggregationBuilder();
56-
$termBucket = new TermBucket('aggregationName', 'fieldName', [], [], [], null, null, null, 1, TermBucket::SORT_ORDER_TERM);
56+
$termBucket = new TermBucket(
57+
'aggregationName',
58+
'fieldName',
59+
[],
60+
[],
61+
[],
62+
null,
63+
null,
64+
null,
65+
1,
66+
TermBucket::SORT_ORDER_TERM
67+
);
68+
69+
$aggregation = $aggBuilder->buildBucket($termBucket);
70+
71+
$this->assertArrayHasKey('terms', $aggregation);
72+
$this->assertEquals('fieldName', $aggregation['terms']['field']);
73+
$this->assertEquals([TermBucket::SORT_ORDER_TERM => SortOrderInterface::SORT_ASC], $aggregation['terms']['order']);
74+
}
75+
76+
/**
77+
* Test the standard term aggregation building sorted by alphabetic order using the deprecated sort order.
78+
*
79+
* @return void
80+
*/
81+
public function testAplhabeticSortOrderTermDeprecatedAggregationBuild()
82+
{
83+
$aggBuilder = $this->getAggregationBuilder();
84+
$termBucket = new TermBucket(
85+
'aggregationName',
86+
'fieldName',
87+
[],
88+
[],
89+
[],
90+
null,
91+
null,
92+
null,
93+
1,
94+
TermBucket::SORT_ORDER_TERM_DEPRECATED
95+
);
5796

5897
$aggregation = $aggBuilder->buildBucket($termBucket);
5998

0 commit comments

Comments
 (0)