9
9
10
10
use Magento \Framework \DB \Helper \Mysql \Fulltext ;
11
11
use Magento \Framework \Search \Adapter \Mysql \Field \ResolverInterface ;
12
- use Magento \Framework \Search \Adapter \Preprocessor \PreprocessorInterface ;
13
12
use Magento \Framework \Search \Adapter \Mysql \Query \Builder \Match as BuilderMatch ;
13
+ use Magento \Framework \Search \Adapter \Preprocessor \PreprocessorInterface ;
14
+ use Magento \Framework \Search \Request \Query \BoolExpression ;
14
15
use Magento \Search \Helper \Data ;
15
16
16
17
/**
@@ -23,6 +24,11 @@ class Match extends BuilderMatch
23
24
*/
24
25
private $ searchHelper ;
25
26
27
+ /**
28
+ * @var string[]
29
+ */
30
+ private $ replaceSymbols = [];
31
+
26
32
/**
27
33
* @param ResolverInterface $resolver
28
34
* @param Fulltext $fulltextHelper
@@ -44,8 +50,33 @@ public function __construct(
44
50
/**
45
51
* @inheritdoc
46
52
*/
47
- protected function getMinimalCharacterLength ( )
53
+ protected function prepareQuery ( $ queryValue , $ conditionType )
48
54
{
49
- return $ this ->searchHelper ->getMinQueryLength ();
55
+ $ queryValue = str_replace ($ this ->replaceSymbols , ' ' , $ queryValue );
56
+ foreach ($ this ->preprocessors as $ preprocessor ) {
57
+ $ queryValue = $ preprocessor ->process ($ queryValue );
58
+ }
59
+
60
+ $ stringPrefix = '' ;
61
+ if ($ conditionType === BoolExpression::QUERY_CONDITION_MUST ) {
62
+ $ stringPrefix = '+ ' ;
63
+ } elseif ($ conditionType === BoolExpression::QUERY_CONDITION_NOT ) {
64
+ $ stringPrefix = '- ' ;
65
+ }
66
+
67
+ $ queryValues = explode (' ' , $ queryValue );
68
+
69
+ foreach ($ queryValues as $ queryKey => $ queryValue ) {
70
+ if (empty ($ queryValue )) {
71
+ unset($ queryValues [$ queryKey ]);
72
+ } else {
73
+ $ stringSuffix = $ this ->searchHelper ->getMinQueryLength () > strlen ($ queryValue ) ? '' : '* ' ;
74
+ $ queryValues [$ queryKey ] = $ stringPrefix . $ queryValue . $ stringSuffix ;
75
+ }
76
+ }
77
+
78
+ $ queryValue = implode (' ' , $ queryValues );
79
+
80
+ return $ queryValue ;
50
81
}
51
82
}
0 commit comments