12
12
use Magento \Framework \Search \Adapter \Mysql \ScoreBuilder ;
13
13
use Magento \Framework \Search \Request \Query \BoolExpression ;
14
14
use Magento \Framework \Search \Request \QueryInterface as RequestQueryInterface ;
15
- use Zend_Db_Expr ;
16
15
17
16
class Match implements QueryInterface
18
17
{
19
- const SPECIAL_CHARACTERS = '-+~/\<> \'":*$#@()!,.?`=%^ ' ;
18
+ const SPECIAL_CHARACTERS = '-+~/ \\ <> \'":*$#@()!,.?`=%&^_ ' ;
20
19
21
20
const MINIMAL_CHARACTER_LENGTH = 3 ;
22
21
23
22
/**
24
23
* @var string[]
25
24
*/
26
- private $ pattern = [];
25
+ private $ replaceSymbols = [];
27
26
28
27
/**
29
28
* @var ResolverInterface
@@ -51,12 +50,7 @@ public function __construct(
51
50
$ fulltextSearchMode = Fulltext::FULLTEXT_MODE_BOOLEAN
52
51
) {
53
52
$ this ->resolver = $ resolver ;
54
- $ characters = str_split (self ::SPECIAL_CHARACTERS , 1 );
55
- foreach ($ characters as $ key => $ value ) {
56
- $ characters [$ key ] = "\\{$ value }" ;
57
- }
58
- $ characters = implode ('' , $ characters );
59
- $ this ->pattern = $ characters = "/([ {$ characters }])/ " ;
53
+ $ this ->replaceSymbols = str_split (self ::SPECIAL_CHARACTERS , 1 );
60
54
$ this ->fulltextHelper = $ fulltextHelper ;
61
55
$ this ->fulltextSearchMode = $ fulltextSearchMode ;
62
56
}
@@ -91,7 +85,7 @@ public function build(
91
85
92
86
$ matchQuery = $ this ->fulltextHelper ->getMatchQuery (
93
87
$ columns ,
94
- new Zend_Db_Expr ( $ queryValue) ,
88
+ $ queryValue ,
95
89
$ this ->fulltextSearchMode
96
90
);
97
91
$ scoreBuilder ->addCondition ($ matchQuery , true );
@@ -112,7 +106,7 @@ public function build(
112
106
*/
113
107
protected function prepareQuery ($ queryValue , $ conditionType )
114
108
{
115
- $ queryValue = preg_replace ($ this ->pattern , '\\\\ $1 ' , $ queryValue );
109
+ $ queryValue = str_replace ($ this ->replaceSymbols , ' ' , $ queryValue );
116
110
117
111
$ stringPrefix = '' ;
118
112
if ($ conditionType === BoolExpression::QUERY_CONDITION_MUST ) {
0 commit comments