Skip to content

Commit 6f5aac8

Browse files
committed
MAGETWO-44555: Exception in Advanced Search if used special symbols
- Added symbols
1 parent 4db5018 commit 6f5aac8

File tree

1 file changed

+5
-11
lines changed
  • lib/internal/Magento/Framework/Search/Adapter/Mysql/Query/Builder

1 file changed

+5
-11
lines changed

lib/internal/Magento/Framework/Search/Adapter/Mysql/Query/Builder/Match.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,17 @@
1212
use Magento\Framework\Search\Adapter\Mysql\ScoreBuilder;
1313
use Magento\Framework\Search\Request\Query\BoolExpression;
1414
use Magento\Framework\Search\Request\QueryInterface as RequestQueryInterface;
15-
use Zend_Db_Expr;
1615

1716
class Match implements QueryInterface
1817
{
19-
const SPECIAL_CHARACTERS = '-+~/\<>\'":*$#@()!,.?`=%^';
18+
const SPECIAL_CHARACTERS = '-+~/\\<>\'":*$#@()!,.?`=%&^_';
2019

2120
const MINIMAL_CHARACTER_LENGTH = 3;
2221

2322
/**
2423
* @var string[]
2524
*/
26-
private $pattern = [];
25+
private $replaceSymbols = [];
2726

2827
/**
2928
* @var ResolverInterface
@@ -51,12 +50,7 @@ public function __construct(
5150
$fulltextSearchMode = Fulltext::FULLTEXT_MODE_BOOLEAN
5251
) {
5352
$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);
6054
$this->fulltextHelper = $fulltextHelper;
6155
$this->fulltextSearchMode = $fulltextSearchMode;
6256
}
@@ -91,7 +85,7 @@ public function build(
9185

9286
$matchQuery = $this->fulltextHelper->getMatchQuery(
9387
$columns,
94-
new Zend_Db_Expr($queryValue),
88+
$queryValue,
9589
$this->fulltextSearchMode
9690
);
9791
$scoreBuilder->addCondition($matchQuery, true);
@@ -112,7 +106,7 @@ public function build(
112106
*/
113107
protected function prepareQuery($queryValue, $conditionType)
114108
{
115-
$queryValue = preg_replace($this->pattern, '\\\\$1', $queryValue);
109+
$queryValue = str_replace($this->replaceSymbols, ' ', $queryValue);
116110

117111
$stringPrefix = '';
118112
if ($conditionType === BoolExpression::QUERY_CONDITION_MUST) {

0 commit comments

Comments
 (0)