This commit is contained in:
team 1
2026-05-10 08:16:19 +02:00
parent 8827a5a13b
commit 7d9a3b2f29
3 changed files with 201 additions and 0 deletions

View File

@@ -218,6 +218,18 @@ final readonly class SearchRepairService
);
}
if (
$requestedAccessoryCodes === []
&& $accessoryCandidates === []
&& $this->asksForBundleOrAccessory($prompt . ' ' . $primaryQuery)
) {
$genericAccessoryQueries = $this->buildGenericAccessoryFocusRepairQueries($primaryQuery, $prompt);
if ($genericAccessoryQueries !== []) {
return $this->normalizeRepairQueries($genericAccessoryQueries, $primaryQuery);
}
}
$topPrimaryName = $primaryShopResults[0]->name ?? '';
$topPrimaryProductNumber = $primaryShopResults[0]->productNumber ?? null;
$topPrimaryPhrase = trim($topPrimaryName . ' ' . ($topPrimaryProductNumber ?? ''));
@@ -269,6 +281,93 @@ final readonly class SearchRepairService
return $this->normalizeRepairQueries($queries, $primaryQuery);
}
/**
* @return string[]
*/
private function buildGenericAccessoryFocusRepairQueries(string $primaryQuery, string $prompt): array
{
$source = trim($primaryQuery) !== '' ? $primaryQuery : $prompt;
$tokens = $this->tokenize($source);
if ($tokens === []) {
return [];
}
$accessoryQueryTokens = $this->buildTokenSet($this->config->getGenericAccessoryFocusQueryTerms());
$accessorySignalTokens = $this->buildTokenSet(array_merge(
$this->config->getAccessoryOrBundleTerms(),
$this->config->getGenericAccessoryFocusQueryTerms()
));
if (!$this->containsAnyToken($tokens, $accessorySignalTokens)) {
return [];
}
$removeTokens = $this->buildTokenSet($this->config->getGenericCandidateTokens());
foreach ($this->buildTokenSet($this->config->getAccessoryOrBundleTerms()) as $token => $_) {
if (!isset($accessoryQueryTokens[$token])) {
$removeTokens[$token] = true;
}
}
$kept = [];
foreach ($tokens as $token) {
if (isset($removeTokens[$token]) || isset($kept[$token])) {
continue;
}
$kept[$token] = $token;
}
if (!$this->containsAnyToken(array_values($kept), $accessoryQueryTokens)) {
foreach ($tokens as $token) {
if (isset($accessoryQueryTokens[$token])) {
$kept[$token] = $token;
break;
}
}
}
if (!$this->containsAnyToken(array_values($kept), $accessoryQueryTokens)) {
return [];
}
$maxTokens = max(2, $this->config->getCandidateWordCountCap());
$queryTokens = array_slice(array_values($kept), 0, $maxTokens);
$query = $this->sanitizeQuery(implode(' ', $queryTokens));
return $query !== '' ? [$query] : [];
}
/** @param string[] $terms */
private function buildTokenSet(array $terms): array
{
$tokens = [];
foreach ($terms as $term) {
foreach ($this->tokenize((string) $term) as $token) {
$tokens[$token] = true;
}
}
return $tokens;
}
/**
* @param string[] $tokens
* @param array<string, true> $tokenSet
*/
private function containsAnyToken(array $tokens, array $tokenSet): bool
{
foreach ($tokens as $token) {
if (isset($tokenSet[$token])) {
return true;
}
}
return false;
}
/**
* @return string[]
*/

View File

@@ -293,6 +293,19 @@ final class SearchRepairConfig
);
}
/** @return string[] */
public function getGenericAccessoryFocusQueryTerms(): array
{
return array_values(array_unique(array_merge(
$this->getAccessoryCandidateTerms(),
$this->genreStringList('product_roles.accessory_product_terms.terms'),
$this->genreStringList('product_roles.requested_accessory_code_terms.terms'),
$this->genreStringList('product_roles.shop_views.accessory_query_terms'),
$this->genreStringList('product_roles.shop_views.accessory_product_terms'),
$this->genreStringList('product_roles.shop_views.accessory_focus_terms')
)));
}
/** @return string[] */
public function getSpecificityBoostTerms(): array
{