Skip to content

Commit 17ae54a

Browse files
committed
ACP2E-8: Search weight is not correctly get applied to SKU attribute
1 parent 5734ca9 commit 17ae54a

File tree

6 files changed

+167
-23
lines changed

6 files changed

+167
-23
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="AdminProductAttributeSetSearchWeightActionGroup">
11+
<annotations>
12+
<description>Set 'Search Weight' value for product attribute</description>
13+
</annotations>
14+
<arguments>
15+
<argument name="value" type="string" defaultValue="2"/>
16+
</arguments>
17+
18+
<scrollToTopOfPage stepKey="scrollToTopOfPage"/>
19+
<click selector="{{StorefrontPropertiesSection.StoreFrontPropertiesTab}}" stepKey="clickStorefrontPropertiesTab"/>
20+
<waitForElementVisible selector="{{AdvancedAttributePropertiesSection.SearchWeight}}" stepKey="waitForSearchWeightValueElementVisible"/>
21+
<selectOption selector="{{AdvancedAttributePropertiesSection.SearchWeight}}" userInput="{{value}}" stepKey="setSearchWeightValue"/>
22+
</actionGroup>
23+
</actionGroups>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
10+
<section name="AdvancedAttributePropertiesSection">
11+
<element name="SearchWeight" type="select" selector="#search_weight"/>
12+
</section>
13+
</sections>
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="StorefrontQuickSearchSkuWithSpecialCharRankingTest">
12+
<annotations>
13+
<features value="Search"/>
14+
<stories value="Search Product on Storefront"/>
15+
<title value="Quick Search should rank product which SKU matches exactly the search term highly in the result"/>
16+
<description value="Quick Search should rank product which SKU matches exactly the search term highly in the result"/>
17+
<severity value="AVERAGE"/>
18+
<useCaseId value="ACP2E-8"/>
19+
<testCaseId value="AC-1259"/>
20+
<group value="SearchEngineElasticsearch"/>
21+
</annotations>
22+
<before>
23+
<!--Create product1-->
24+
<createData entity="SimpleTwo" stepKey="product1">
25+
<field key="sku">ZXH-QJ185</field>
26+
</createData>
27+
<!--Create product2-->
28+
<createData entity="SimpleTwo" stepKey="product2">
29+
<field key="name">ZXH-QJ185</field>
30+
</createData>
31+
<!--Login as admin-->
32+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
33+
<!--Open "SKU" attribute in admin-->
34+
<actionGroup ref="OpenProductAttributeFromSearchResultInGridActionGroup" stepKey="OpenSkuAttribute">
35+
<argument name="productAttributeCode" value="sku"/>
36+
</actionGroup>
37+
<!--Set "SKU" attribute search weight-->
38+
<actionGroup ref="AdminProductAttributeSetSearchWeightActionGroup" stepKey="setSkuSearchWeight">
39+
<argument name="value" value="10"/>
40+
</actionGroup>
41+
<!--Save "SKU" attribute-->
42+
<actionGroup ref="SaveProductAttributeActionGroup" stepKey="saveSkuAttribute"/>
43+
<!--Open "Name" attribute in admin-->
44+
<actionGroup ref="OpenProductAttributeFromSearchResultInGridActionGroup" stepKey="OpenNameAttribute">
45+
<argument name="productAttributeCode" value="name"/>
46+
</actionGroup>
47+
<!--Set "Name" attribute search weight-->
48+
<actionGroup ref="AdminProductAttributeSetSearchWeightActionGroup" stepKey="setNameSearchWeight">
49+
<argument name="value" value="2"/>
50+
</actionGroup>
51+
<!--Save "Name" attribute-->
52+
<actionGroup ref="SaveProductAttributeActionGroup" stepKey="saveNameAttribute"/>
53+
<!--Reindex-->
54+
<actionGroup ref="CliIndexerReindexActionGroup" stepKey="reindex">
55+
<argument name="indices" value=""/>
56+
</actionGroup>
57+
<!--Clean cache-->
58+
<actionGroup ref="CliCacheCleanActionGroup" stepKey="flushCache">
59+
<argument name="tags" value=""/>
60+
</actionGroup>
61+
</before>
62+
<after>
63+
<!--Delete product1-->
64+
<deleteData createDataKey="product1" stepKey="deleteProduct1"/>
65+
<!--Delete product2-->
66+
<deleteData createDataKey="product2" stepKey="deleteProduct2"/>
67+
<!--Open "SKU" attribute in admin-->
68+
<actionGroup ref="OpenProductAttributeFromSearchResultInGridActionGroup" stepKey="OpenSkuAttribute">
69+
<argument name="productAttributeCode" value="sku"/>
70+
</actionGroup>
71+
<!--Reset "SKU" attribute search weight-->
72+
<actionGroup ref="AdminProductAttributeSetSearchWeightActionGroup" stepKey="setSkuSearchWeight">
73+
<argument name="value" value="6"/>
74+
</actionGroup>
75+
<!--Save "SKU" attribute-->
76+
<actionGroup ref="SaveProductAttributeActionGroup" stepKey="saveSkuAttribute"/>
77+
<!--Open "Name" attribute in admin-->
78+
<actionGroup ref="OpenProductAttributeFromSearchResultInGridActionGroup" stepKey="OpenNameAttribute">
79+
<argument name="productAttributeCode" value="name"/>
80+
</actionGroup>
81+
<!--Reset "Name" attribute search weight-->
82+
<actionGroup ref="AdminProductAttributeSetSearchWeightActionGroup" stepKey="setNameSearchWeight">
83+
<argument name="value" value="5"/>
84+
</actionGroup>
85+
<!--Save "Name" attribute-->
86+
<actionGroup ref="SaveProductAttributeActionGroup" stepKey="saveNameAttribute"/>
87+
<!--Clear grid filter-->
88+
<actionGroup ref="ClearFiltersAdminDataGridActionGroup" stepKey="clearFilter"/>
89+
<!--Logout from admin-->
90+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logoutFromAdmin"/>
91+
</after>
92+
<!--Navigate to home page-->
93+
<actionGroup ref="StorefrontOpenHomePageActionGroup" stepKey="goToHomePage"/>
94+
<!--Search for word "ZXH-QJ185"-->
95+
<actionGroup ref="StorefrontCheckQuickSearchStringActionGroup" stepKey="search">
96+
<argument name="phrase" value="ZXH-QJ185"/>
97+
</actionGroup>
98+
<!--Assert that product1 is first in the search result-->
99+
<actionGroup ref="StorefrontQuickSearchCheckProductNameInGridActionGroup" stepKey="assertProduct1Position">
100+
<argument name="productName" value="$product1.name$"/>
101+
<argument name="index" value="1"/>
102+
</actionGroup>
103+
<!--Assert that product2 is second in the search result-->
104+
<actionGroup ref="StorefrontQuickSearchCheckProductNameInGridActionGroup" stepKey="assertProduct2Position">
105+
<argument name="productName" value="$product2.name$"/>
106+
<argument name="index" value="2"/>
107+
</actionGroup>
108+
</test>
109+
</tests>
110+

app/code/Magento/Elasticsearch/Model/Adapter/Index/Builder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ public function build()
6363
),
6464
'char_filter' => array_keys($charFilter)
6565
],
66-
// this analyzer must not include stemmer filter
66+
// this analyzer must not include keyword_repeat amd stemmer filters
6767
'prefix_search' => [
6868
'type' => 'custom',
6969
'tokenizer' => key($tokenizer),
70-
'filter' => ['lowercase', 'keyword_repeat', 'asciifolding'],
70+
'filter' => ['lowercase', 'asciifolding'],
7171
'char_filter' => array_keys($charFilter)
7272
],
7373
'sku' => [
@@ -78,11 +78,11 @@ public function build()
7878
array_keys($filter)
7979
),
8080
],
81-
// this analyzer must not include stemmer filter
81+
// this analyzer must not include keyword_repeat amd stemmer filters
8282
'sku_prefix_search' => [
8383
'type' => 'custom',
8484
'tokenizer' => 'keyword',
85-
'filter' => ['lowercase', 'keyword_repeat', 'asciifolding']
85+
'filter' => ['lowercase', 'asciifolding']
8686
]
8787
],
8888
'tokenizer' => $tokenizer,

app/code/Magento/Elasticsearch/SearchAdapter/Query/ValueTransformer/TextTransformer.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,10 @@ public function __construct(array $preprocessors = [])
4141
*/
4242
public function transform(string $value): string
4343
{
44-
$value = $this->escape($value);
4544
foreach ($this->preprocessors as $preprocessor) {
4645
$value = $preprocessor->process($value);
4746
}
4847

4948
return $value;
5049
}
51-
52-
/**
53-
* Escape a value for special query characters such as ':', '(', ')', '*', '?', etc.
54-
*
55-
* @param string $value
56-
* @return string
57-
*/
58-
private function escape(string $value): string
59-
{
60-
$pattern = '/(\+|-|&&|\|\||!|\(|\)|\{|}|\[|]|\^|"|~|\/|\*|\?|:|\\\)/';
61-
$replace = '\\\$1';
62-
63-
return preg_replace($pattern, $replace, $value);
64-
}
6550
}

app/code/Magento/Elasticsearch/Test/Unit/SearchAdapter/Query/ValueTransformer/TextTransformerTest.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\Elasticsearch\Test\Unit\SearchAdapter\Query\ValueTransformer;
99

10+
use Magento\Framework\Search\Adapter\Preprocessor\PreprocessorInterface;
1011
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1112
use Magento\Elasticsearch\SearchAdapter\Query\ValueTransformer\TextTransformer;
1213
use PHPUnit\Framework\TestCase;
@@ -21,17 +22,25 @@ class TextTransformerTest extends TestCase
2122
*/
2223
protected $model;
2324

25+
/**
26+
* @var PreprocessorInterface
27+
*/
28+
private $processorMock;
29+
2430
/**
2531
* Setup method
2632
* @return void
2733
*/
2834
public function setUp(): void
2935
{
3036
$objectManagerHelper = new ObjectManagerHelper($this);
37+
$this->processorMock = $this->createMock(PreprocessorInterface::class);
3138
$this->model = $objectManagerHelper->getObject(
3239
TextTransformer::class,
3340
[
34-
'$preprocessors' => [],
41+
'preprocessors' => [
42+
$this->processorMock
43+
],
3544
]
3645
);
3746
}
@@ -46,6 +55,10 @@ public function setUp(): void
4655
*/
4756
public function testTransform(string $value, string $expected): void
4857
{
58+
$this->processorMock->expects($this->once())
59+
->method('process')
60+
->with($value)
61+
->willReturnCallback('strtolower');
4962
$result = $this->model->transform($value);
5063
$this->assertEquals($expected, $result);
5164
}
@@ -58,9 +71,9 @@ public function testTransform(string $value, string $expected): void
5871
public function valuesDataProvider(): array
5972
{
6073
return [
61-
['Laptop^camera{microphone}', 'Laptop\^camera\{microphone\}'],
62-
['Birthday 25-Pack w/ Greatest of All Time Cupcake', 'Birthday 25\-Pack w\/ Greatest of All Time Cupcake'],
63-
['Retro vinyl record ~d123 *star', 'Retro vinyl record \~d123 \*star'],
74+
['Laptop^camera{microphone}', 'laptop^camera{microphone}'],
75+
['Birthday 25-Pack w/ Greatest of All Time Cupcake', 'birthday 25-pack w/ greatest of all time cupcake'],
76+
['Retro vinyl record ~d123 *star', 'retro vinyl record ~d123 *star'],
6477
];
6578
}
6679
}

0 commit comments

Comments
 (0)