Skip to content

Commit e1040cc

Browse files
ENGCOM-8303: Fix exception which is thrown on search results page #30318
- Merge Pull Request #30318 from wojtekn/magento2:fix_search_results_page_exception - Merged commits: 1. ce1263d 2. ccec05a 3. 970d179 4. 38c4a3e 5. 88f6101
2 parents a92dee7 + 88f6101 commit e1040cc

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

app/code/Magento/Search/Model/SynonymAnalyzer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function __construct(SynonymReader $synReader)
4242
* 3 => [ 0 => "british", 1 => "english" ],
4343
* 4 => [ 0 => "queen", 1 => "monarch" ]
4444
* ]
45+
*
4546
* @param string $phrase
4647
* @return array
4748
* @throws \Magento\Framework\Exception\LocalizedException
@@ -136,6 +137,9 @@ private function getSearchPattern(array $words): string
136137
{
137138
$patterns = [];
138139
for ($lastItem = count($words); $lastItem > 0; $lastItem--) {
140+
$words = array_map(function ($word) {
141+
return preg_quote($word, '/');
142+
}, $words);
139143
$phrase = implode("\s+", \array_slice($words, 0, $lastItem));
140144
$patterns[] = '^' . $phrase . ',';
141145
$patterns[] = ',' . $phrase . ',';

app/code/Magento/Search/Test/Unit/Model/SynonymAnalyzerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ protected function setUp(): void
4949
*/
5050
public function testGetSynonymsForPhrase()
5151
{
52-
$phrase = 'Elizabeth is the british queen';
52+
$phrase = 'Elizabeth/Angela is the british queen';
5353
$expected = [
54-
0 => [ 0 => "Elizabeth" ],
54+
0 => [ 0 => "Elizabeth/Angela" ],
5555
1 => [ 0 => "is" ],
5656
2 => [ 0 => "the" ],
5757
3 => [ 0 => "british", 1 => "english" ],

dev/tests/integration/testsuite/Magento/Search/Model/SynonymAnalyzerTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ public static function loadGetSynonymsForPhraseDataProvider()
7878
'phrase' => 'schlicht',
7979
'expectedResult' => [['schlicht', 'natürlich']]
8080
],
81+
'withSlashInSearchPhrase' => [
82+
'phrase' => 'orange hill/peak',
83+
'expectedResult' => [['orange', 'magento'], ['hill/peak']]
84+
],
8185
];
8286
}
8387

0 commit comments

Comments
 (0)