Skip to content

Commit 061aa98

Browse files
committed
MAGETWO-58764: [GitHub] Minimal Query Length For Catalog Search #6681
1 parent 3188c0b commit 061aa98

File tree

2 files changed

+35
-14
lines changed
  • app/code/Magento/CatalogGraphQl/Model/Search/Adapter/Mysql/Query/Builder
  • lib/internal/Magento/Framework/Search/Adapter/Mysql/Query/Builder

2 files changed

+35
-14
lines changed

app/code/Magento/CatalogGraphQl/Model/Search/Adapter/Mysql/Query/Builder/Match.php

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99

1010
use Magento\Framework\DB\Helper\Mysql\Fulltext;
1111
use Magento\Framework\Search\Adapter\Mysql\Field\ResolverInterface;
12-
use Magento\Framework\Search\Adapter\Preprocessor\PreprocessorInterface;
1312
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;
1415
use Magento\Search\Helper\Data;
1516

1617
/**
@@ -23,6 +24,11 @@ class Match extends BuilderMatch
2324
*/
2425
private $searchHelper;
2526

27+
/**
28+
* @var string[]
29+
*/
30+
private $replaceSymbols = [];
31+
2632
/**
2733
* @param ResolverInterface $resolver
2834
* @param Fulltext $fulltextHelper
@@ -44,8 +50,33 @@ public function __construct(
4450
/**
4551
* @inheritdoc
4652
*/
47-
protected function getMinimalCharacterLength()
53+
protected function prepareQuery($queryValue, $conditionType)
4854
{
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;
5081
}
5182
}

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ protected function prepareQuery($queryValue, $conditionType)
148148
if (empty($queryValue)) {
149149
unset($queryValues[$queryKey]);
150150
} else {
151-
$stringSuffix = $this->getMinimalCharacterLength() > strlen($queryValue) ? '' : '*';
151+
$stringSuffix = self::MINIMAL_CHARACTER_LENGTH > strlen($queryValue) ? '' : '*';
152152
$queryValues[$queryKey] = $stringPrefix . $queryValue . $stringSuffix;
153153
}
154154
}
@@ -157,14 +157,4 @@ protected function prepareQuery($queryValue, $conditionType)
157157

158158
return $queryValue;
159159
}
160-
161-
/**
162-
* Retrieves minimal character length
163-
*
164-
* @return int
165-
*/
166-
protected function getMinimalCharacterLength()
167-
{
168-
return self::MINIMAL_CHARACTER_LENGTH;
169-
}
170160
}

0 commit comments

Comments
 (0)