p83
This commit is contained in:
@@ -9,6 +9,7 @@ use App\Commerce\ProductRoleResolver;
|
||||
use App\Commerce\SearchRepairService;
|
||||
use App\Commerce\ShopSearchService;
|
||||
use App\Config\AgentRunnerConfig;
|
||||
use App\Config\CommerceQueryParserConfig;
|
||||
use App\Config\LanguageCleanupConfig;
|
||||
use App\Context\ContextService;
|
||||
use App\Context\UrlAnalyzer;
|
||||
@@ -33,6 +34,7 @@ final readonly class AgentRunner
|
||||
private SearchRepairService $searchRepairService,
|
||||
private ReferenceAnchorExtractor $referenceAnchorExtractor,
|
||||
private CommerceIntentLite $commerceIntentLite,
|
||||
private CommerceQueryParserConfig $commerceQueryParserConfig,
|
||||
private OllamaClient $ollamaClient,
|
||||
private LoggerInterface $agentLogger,
|
||||
private AgentRunnerConfig $agentRunnerConfig,
|
||||
@@ -1651,6 +1653,7 @@ final readonly class AgentRunner
|
||||
: $this->preserveCurrentInputShopQueryTerms($prompt, $shopSearchQuery);
|
||||
|
||||
$query = $this->cleanupDirectProductAttributeShopQuery($prompt, $query);
|
||||
$query = $this->applyConfiguredShopSearchTokenCorrections($query);
|
||||
|
||||
return $this->cleanupShopQueryStopwords($query);
|
||||
}
|
||||
@@ -1988,14 +1991,17 @@ final readonly class AgentRunner
|
||||
$shopSearchQuery = trim($shopSearchQuery);
|
||||
|
||||
if ($shopSearchQuery === '' || !$this->agentRunnerConfig->isShopQueryCurrentInputPreservationEnabled()) {
|
||||
return $shopSearchQuery;
|
||||
return $this->applyConfiguredShopSearchTokenCorrections($shopSearchQuery);
|
||||
}
|
||||
|
||||
$promptTokens = array_fill_keys($this->tokenizeShopQueryCandidate($prompt), true);
|
||||
$queryTokens = array_fill_keys($this->tokenizeShopQueryCandidate($shopSearchQuery), true);
|
||||
$correctedPrompt = $this->applyConfiguredShopSearchTokenCorrections($prompt);
|
||||
$correctedShopSearchQuery = $this->applyConfiguredShopSearchTokenCorrections($shopSearchQuery);
|
||||
|
||||
$promptTokens = array_fill_keys($this->tokenizeShopQueryCandidate($correctedPrompt), true);
|
||||
$queryTokens = array_fill_keys($this->tokenizeShopQueryCandidate($correctedShopSearchQuery), true);
|
||||
|
||||
if ($promptTokens === [] || $queryTokens === []) {
|
||||
return $shopSearchQuery;
|
||||
return $correctedShopSearchQuery;
|
||||
}
|
||||
|
||||
$appendTokens = [];
|
||||
@@ -2023,10 +2029,38 @@ final readonly class AgentRunner
|
||||
}
|
||||
|
||||
if ($appendTokens === []) {
|
||||
return $shopSearchQuery;
|
||||
return $correctedShopSearchQuery;
|
||||
}
|
||||
|
||||
return trim($shopSearchQuery . ' ' . implode(' ', array_values($appendTokens)));
|
||||
return trim($correctedShopSearchQuery . ' ' . implode(' ', array_values($appendTokens)));
|
||||
}
|
||||
|
||||
private function applyConfiguredShopSearchTokenCorrections(string $text): string
|
||||
{
|
||||
$text = trim($text);
|
||||
|
||||
if ($text === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
foreach ($this->commerceQueryParserConfig->getSearchTokenCorrections() as $from => $to) {
|
||||
$from = trim((string) $from);
|
||||
$to = trim((string) $to);
|
||||
|
||||
if ($from === '' || $to === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$text = preg_replace(
|
||||
'/\b' . preg_quote($from, '/') . '\b/u',
|
||||
$to,
|
||||
$text
|
||||
) ?? $text;
|
||||
}
|
||||
|
||||
$text = preg_replace('/\s+/u', ' ', $text) ?? $text;
|
||||
|
||||
return trim($text);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user