File tree Expand file tree Collapse file tree 2 files changed +20
-3
lines changed
app/code/Magento/CatalogSearch
Test/Unit/Model/Search/Request Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Original file line number Diff line number Diff 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 );
Original file line number Diff line number Diff 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 ]
You can’t perform that action at this time.
0 commit comments