Skip to content

Commit 4acfde7

Browse files
committed
Merge branch 'ACP2E-1499' of https://github.com/magento-l3/magento2ce into PR-L3-2023-01-31
2 parents 78ac663 + ab29fc0 commit 4acfde7

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

app/code/Magento/CatalogSearch/Model/Search/Request/PartialSearchModifier.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ public function modify(array $requests): array
4141
if ($matches) {
4242
foreach ($matches as $index => $match) {
4343
$field = $match['field'] ?? null;
44-
if ($field && $field !== '*' && !isset($attributes[$field])) {
45-
unset($matches[$index]);
44+
if ($field && $field !== '*') {
45+
if (!isset($attributes[$field])) {
46+
unset($matches[$index]);
47+
continue;
48+
}
49+
$matches[$index]['boost'] = $attributes[$field]->getSearchWeight() ?: 1;
4650
}
4751
}
4852
$requests[$code]['queries']['partial_search']['match'] = array_values($matches);

app/code/Magento/CatalogSearch/Test/Unit/Model/Search/Request/PartialSearchModifierTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,16 @@ protected function setUp(): void
5555
public function testModify(array $attributes, array $requests, array $expected): void
5656
{
5757
$items = [];
58+
$searchWeight = 10;
5859
foreach ($attributes as $attribute) {
59-
$item = $this->getMockForAbstractClass(\Magento\Eav\Api\Data\AttributeInterface::class);
60+
$item = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class)
61+
->setMethods(['getAttributeCode', 'getSearchWeight'])
62+
->disableOriginalConstructor()
63+
->getMock();
6064
$item->method('getAttributeCode')
6165
->willReturn($attribute);
66+
$item->method('getSearchWeight')
67+
->willReturn($searchWeight);
6268
$items[] = $item;
6369
}
6470
$reflectionProperty = new \ReflectionProperty($this->collection, '_items');
@@ -76,6 +82,7 @@ public function modifyDataProvider(): array
7682
[
7783
[
7884
'name',
85+
'sku',
7986
],
8087
[
8188
'search_1' => [
@@ -133,9 +140,15 @@ public function modifyDataProvider(): array
133140
[
134141
'field' => '*'
135142
],
143+
[
144+
'field' => 'sku',
145+
'matchCondition' => 'match_phrase_prefix',
146+
'boost' => 10
147+
],
136148
[
137149
'field' => 'name',
138150
'matchCondition' => 'match_phrase_prefix',
151+
'boost' => 10
139152
],
140153
]
141154
]

0 commit comments

Comments
 (0)