optimize retrieval
This commit is contained in:
@@ -131,13 +131,13 @@ final readonly class CommerceQueryParser
|
||||
return [];
|
||||
}
|
||||
|
||||
foreach ($matches[1] as $size) {
|
||||
$sizes[] = trim($size);
|
||||
foreach ($matches[1] ?? [] as $size) {
|
||||
$sizes[] = trim((string) $size);
|
||||
}
|
||||
|
||||
if (preg_match_all($this->intentConfig->getSizeTokenValuePattern(), $prompt, $tokenMatches) !== false) {
|
||||
foreach ($tokenMatches[1] as $sizeToken) {
|
||||
$sizes[] = trim($sizeToken);
|
||||
foreach ($tokenMatches[0] ?? [] as $sizeToken) {
|
||||
$sizes[] = trim((string) $sizeToken);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,6 +242,7 @@ final readonly class CommerceQueryParser
|
||||
fn(string $token): bool => mb_strlen($token) >= $this->config->getMinDirectProductTokenLength()
|
||||
);
|
||||
|
||||
$tokens = $this->filterSearchTokens($tokens);
|
||||
$tokens = array_values(array_unique($tokens));
|
||||
|
||||
return trim(implode(' ', $tokens));
|
||||
@@ -286,6 +287,10 @@ final readonly class CommerceQueryParser
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->isSearchControlToken($token)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$tokens[$token] = $token;
|
||||
}
|
||||
}
|
||||
@@ -299,14 +304,38 @@ final readonly class CommerceQueryParser
|
||||
*/
|
||||
private function filterSearchTokens(array $tokens): array
|
||||
{
|
||||
$stopWords = $this->config->getFilterSearchTokens();
|
||||
|
||||
return array_values(array_filter(
|
||||
$tokens,
|
||||
static fn(string $token): bool => !in_array($token, $stopWords, true)
|
||||
fn(string $token): bool => !$this->isSearchControlToken($token)
|
||||
));
|
||||
}
|
||||
|
||||
private function isSearchControlToken(string $token): bool
|
||||
{
|
||||
$token = trim(mb_strtolower($token));
|
||||
|
||||
if ($token === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (in_array($token, $this->config->getFilterSearchTokens(), true)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return in_array($token, [
|
||||
'shop',
|
||||
'store',
|
||||
'produkt',
|
||||
'produkte',
|
||||
'artikel',
|
||||
'kaufen',
|
||||
'kaufe',
|
||||
'bestellen',
|
||||
'bestelle',
|
||||
'online',
|
||||
], true);
|
||||
}
|
||||
|
||||
private function isDirectProductQuery(string $prompt): bool
|
||||
{
|
||||
if ($prompt === '') {
|
||||
@@ -328,8 +357,10 @@ final readonly class CommerceQueryParser
|
||||
PREG_SPLIT_NO_EMPTY
|
||||
) ?: [];
|
||||
|
||||
$tokens = $this->filterSearchTokens($tokens);
|
||||
|
||||
return count($tokens) <= $this->config->getDirectProductMaxTokens()
|
||||
&& preg_match($this->config->getDirectProductDigitPattern(), $prompt) === 1;
|
||||
&& preg_match($this->config->getDirectProductDigitPattern(), implode(' ', $tokens)) === 1;
|
||||
}
|
||||
|
||||
private function containsModelLikePhrase(string $text): bool
|
||||
|
||||
Reference in New Issue
Block a user