Skip to content

Commit 965fec1

Browse files
authored
Merge pull request #3962 from magento-obsessive-owls/MAGETWO-98738
2 parents f8f2036 + aeb4243 commit 965fec1

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

app/code/Magento/Search/Model/ResourceModel/SynonymReader.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ protected function _construct()
8585
*/
8686
private function queryByPhrase($phrase)
8787
{
88+
$phrase = $this->fullTextSelect->removeSpecialCharacters($phrase);
8889
$matchQuery = $this->fullTextSelect->getMatchQuery(
8990
['synonyms' => 'synonyms'],
9091
$phrase,

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public static function loadByPhraseDataProvider()
3131
[
3232
'ELIZABETH', []
3333
],
34+
[
35+
'-+<(ELIZABETH)>*~', []
36+
],
3437
[
3538
'ENGLISH', [['synonyms' => 'british,english', 'store_id' => 1, 'website_id' => 0]]
3639
],
@@ -43,6 +46,9 @@ public static function loadByPhraseDataProvider()
4346
[
4447
'Monarch', [['synonyms' => 'queen,monarch', 'store_id' => 1, 'website_id' => 0]]
4548
],
49+
[
50+
'-+<(Monarch)>*~', [['synonyms' => 'queen,monarch', 'store_id' => 1, 'website_id' => 0]]
51+
],
4652
[
4753
'MONARCH English', [
4854
['synonyms' => 'queen,monarch', 'store_id' => 1, 'website_id' => 0],

lib/internal/Magento/Framework/DB/Helper/Mysql/Fulltext.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,18 @@
77

88
use Magento\Framework\App\ResourceConnection;
99

10+
/**
11+
* MySQL Fulltext Query Builder
12+
*/
1013
class Fulltext
1114
{
15+
/**
16+
* Characters that have special meaning in fulltext match syntax
17+
*
18+
* @var string
19+
*/
20+
const SPECIAL_CHARACTERS = '-+<>*()~';
21+
1222
/**
1323
* FULLTEXT search in MySQL search mode "natural language"
1424
*/
@@ -51,7 +61,7 @@ public function __construct(ResourceConnection $resource)
5161
{
5262
$this->connection = $resource->getConnection();
5363
}
54-
64+
5565
/**
5666
* Method for FULLTEXT search in Mysql, will generated MATCH ($columns) AGAINST ('$expression' $mode)
5767
*
@@ -73,8 +83,7 @@ public function getMatchQuery($columns, $expression, $mode = self::FULLTEXT_MODE
7383
}
7484

7585
/**
76-
* Method for FULLTEXT search in Mysql, will added generated
77-
* MATCH ($columns) AGAINST ('$expression' $mode) to where clause
86+
* Method for FULLTEXT search in Mysql; will add generated MATCH ($columns) AGAINST ('$expression' $mode) to $select
7887
*
7988
* @param \Magento\Framework\DB\Select $select
8089
* @param string|string[] $columns Columns which add to MATCH ()
@@ -95,4 +104,15 @@ public function match($select, $columns, $expression, $isCondition = true, $mode
95104

96105
return $select;
97106
}
107+
108+
/**
109+
* Remove special characters from fulltext query expression
110+
*
111+
* @param string $expression
112+
* @return string
113+
*/
114+
public function removeSpecialCharacters($expression)
115+
{
116+
return str_replace(str_split(static::SPECIAL_CHARACTERS), '', $expression);
117+
}
98118
}

0 commit comments

Comments
 (0)