optimize cleanup search query shop api extends part 2
This commit is contained in:
@@ -79,7 +79,6 @@ final readonly class CommerceQueryParser
|
||||
private function normalize(string $prompt): string
|
||||
{
|
||||
$value = $this->textNormalizer->normalize($prompt);
|
||||
$value = $this->queryCleaner->clean($value);
|
||||
$value = mb_strtolower(trim($value));
|
||||
$value = str_replace(
|
||||
$this->config->getNormalizationSearch(),
|
||||
@@ -274,7 +273,16 @@ final readonly class CommerceQueryParser
|
||||
for ($offset = 1; $offset <= $this->config->getModelContextTokenWindow(); $offset++) {
|
||||
$previousIndex = $index - $offset;
|
||||
|
||||
if (!isset($tokens[$previousIndex]) || !$this->isLikelyModelContextToken($tokens[$previousIndex])) {
|
||||
if (!isset($tokens[$previousIndex])) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ($this->isSemanticShopToken($tokens[$previousIndex])) {
|
||||
$keep[$previousIndex] = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$this->isLikelyModelContextToken($tokens[$previousIndex])) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -287,7 +295,7 @@ final readonly class CommerceQueryParser
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->isSemanticShopToken($token) || $this->isKnownBrandToken($token)) {
|
||||
if ($this->isSemanticShopToken($token) || $this->isKnownBrandToken($token) || $this->isMeasurementValueToken($token)) {
|
||||
$keep[$index] = true;
|
||||
}
|
||||
}
|
||||
@@ -314,6 +322,10 @@ final readonly class CommerceQueryParser
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->isMeasurementValueToken($token)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (preg_match($this->config->getContainsDigitPattern(), $token) === 1) {
|
||||
return false;
|
||||
}
|
||||
@@ -334,6 +346,11 @@ final readonly class CommerceQueryParser
|
||||
return preg_match($this->config->getModelNumberTokenPattern(), $token) === 1;
|
||||
}
|
||||
|
||||
private function isMeasurementValueToken(string $token): bool
|
||||
{
|
||||
return preg_match($this->config->getMeasurementValueTokenPattern(), $token) === 1;
|
||||
}
|
||||
|
||||
private function isLikelyModelContextToken(string $token): bool
|
||||
{
|
||||
if ($this->isQueryNoiseToken($token)) {
|
||||
|
||||
Reference in New Issue
Block a user