harden history find tokens
This commit is contained in:
@@ -527,6 +527,14 @@ final readonly class RetriexEffectiveConfigProvider
|
||||
'enabled' => $this->searchRepairConfig->isEnabled(),
|
||||
'max_repair_queries' => $this->searchRepairConfig->getMaxRepairQueries(),
|
||||
'min_primary_results_without_repair' => $this->searchRepairConfig->getMinPrimaryResultsWithoutRepair(),
|
||||
'strict_requested_accessory_code_repair' => $this->searchRepairConfig->shouldRestrictRequestedAccessoryCodeRepair(),
|
||||
'prefer_prompt_anchored_model_for_requested_accessory_code' => $this->searchRepairConfig->shouldPreferPromptAnchoredModelForRequestedAccessoryCode(),
|
||||
'requested_accessory_code_fallback_query_templates' => $this->searchRepairConfig->getRequestedAccessoryCodeFallbackQueryTemplates(),
|
||||
'requested_accessory_code_fallback_terms' => $this->searchRepairConfig->getRequestedAccessoryCodeFallbackTerms(),
|
||||
'requested_accessory_code_context_prefix_terms' => $this->searchRepairConfig->getRequestedAccessoryCodeContextPrefixTerms(),
|
||||
'requested_accessory_code_proximity_window' => $this->searchRepairConfig->getRequestedAccessoryCodeProximityWindow(),
|
||||
'specific_model_candidate_patterns' => $this->searchRepairConfig->getSpecificModelCandidatePatterns(),
|
||||
'model_candidate_exclude_terms' => $this->searchRepairConfig->getModelCandidateExcludeTerms(),
|
||||
'generic_candidate_tokens' => $this->searchRepairConfig->getGenericCandidateTokens(),
|
||||
'accessory_candidate_terms' => $this->searchRepairConfig->getAccessoryCandidateTerms(),
|
||||
'accessory_or_bundle_terms' => $this->searchRepairConfig->getAccessoryOrBundleTerms(),
|
||||
@@ -546,6 +554,7 @@ final readonly class RetriexEffectiveConfigProvider
|
||||
'patterns' => [
|
||||
'model_candidate' => $this->searchRepairConfig->getModelCandidatePattern(),
|
||||
'accessory_candidate' => $this->searchRepairConfig->getAccessoryCandidatePattern(),
|
||||
'requested_accessory_code' => $this->searchRepairConfig->getRequestedAccessoryCodePattern(),
|
||||
'accessory_or_bundle' => $this->searchRepairConfig->getAccessoryOrBundlePattern(),
|
||||
'model_like' => $this->searchRepairConfig->getModelLikePattern(),
|
||||
'specificity_boost' => $this->searchRepairConfig->getSpecificityBoostPattern(),
|
||||
|
||||
@@ -85,6 +85,66 @@ final class SearchRepairConfig
|
||||
return $this->minPrimaryResultsWithoutRepair;
|
||||
}
|
||||
|
||||
public function shouldRestrictRequestedAccessoryCodeRepair(): bool
|
||||
{
|
||||
return $this->bool('strict_requested_accessory_code_repair', true);
|
||||
}
|
||||
|
||||
public function shouldPreferPromptAnchoredModelForRequestedAccessoryCode(): bool
|
||||
{
|
||||
return $this->bool('prefer_prompt_anchored_model_for_requested_accessory_code', true);
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
public function getRequestedAccessoryCodeFallbackQueryTemplates(): array
|
||||
{
|
||||
return $this->stringList(
|
||||
'requested_accessory_code_fallback_query_templates',
|
||||
['{term} {code}']
|
||||
);
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
public function getRequestedAccessoryCodeFallbackTerms(): array
|
||||
{
|
||||
return $this->stringList(
|
||||
'requested_accessory_code_fallback_terms',
|
||||
$this->getAccessoryCandidateTerms()
|
||||
);
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
public function getRequestedAccessoryCodeContextPrefixTerms(): array
|
||||
{
|
||||
return $this->stringList(
|
||||
'requested_accessory_code_context_prefix_terms',
|
||||
$this->getAccessoryCandidateTerms()
|
||||
);
|
||||
}
|
||||
|
||||
public function getRequestedAccessoryCodeProximityWindow(): int
|
||||
{
|
||||
return $this->int('requested_accessory_code_proximity_window', 1600);
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
public function getSpecificModelCandidatePatterns(): array
|
||||
{
|
||||
return $this->stringList(
|
||||
'specific_model_candidate_patterns',
|
||||
[$this->getModelLikePattern()]
|
||||
);
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
public function getModelCandidateExcludeTerms(): array
|
||||
{
|
||||
return $this->stringList(
|
||||
'model_candidate_exclude_terms',
|
||||
array_merge($this->getAccessoryCandidateTerms(), ['verfuegbarkeit', 'verfügbarkeit', 'shop'])
|
||||
);
|
||||
}
|
||||
|
||||
public function getTopProductLogLimit(): int
|
||||
{
|
||||
return 3;
|
||||
@@ -100,6 +160,21 @@ final class SearchRepairConfig
|
||||
return '/\b((?:' . implode('|', $this->getAccessoryCandidateTerms()) . ')\s+\d{1,5}[A-Za-z0-9\-]*)\b/iu';
|
||||
}
|
||||
|
||||
public function getRequestedAccessoryCodePattern(): string
|
||||
{
|
||||
$fallbackTerms = array_map(
|
||||
static fn(string $term): string => preg_quote($term, '/'),
|
||||
$this->getRequestedAccessoryCodeContextPrefixTerms()
|
||||
);
|
||||
$fallbackTerms = array_filter($fallbackTerms, static fn(string $term): bool => $term !== '');
|
||||
|
||||
$fallbackPattern = $fallbackTerms === []
|
||||
? '/\b([A-Za-z]{0,3}\s*\d{1,5}[A-Za-z0-9\-]*)\b/iu'
|
||||
: '/\b(?:' . implode('|', $fallbackTerms) . ')\s*([A-Za-z]{0,3}\s*\d{1,5}[A-Za-z0-9\-]*)\b/iu';
|
||||
|
||||
return $this->string('requested_accessory_code_pattern', $fallbackPattern);
|
||||
}
|
||||
|
||||
public function getAccessoryOrBundlePattern(): string
|
||||
{
|
||||
return '/\b(' . implode('|', $this->getAccessoryOrBundleTerms()) . ')\b/iu';
|
||||
@@ -232,6 +307,59 @@ final class SearchRepairConfig
|
||||
return $this->vocabulary?->view($path, $fallback) ?? $fallback;
|
||||
}
|
||||
|
||||
private function string(string $key, string $default): string
|
||||
{
|
||||
$value = $this->config[$key] ?? $default;
|
||||
|
||||
if (!is_scalar($value)) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
$value = trim((string) $value);
|
||||
|
||||
return $value !== '' ? $value : $default;
|
||||
}
|
||||
|
||||
private function int(string $key, int $default): int
|
||||
{
|
||||
$value = $this->config[$key] ?? $default;
|
||||
|
||||
if (is_int($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (is_numeric($value)) {
|
||||
return (int) $value;
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
private function bool(string $key, bool $default): bool
|
||||
{
|
||||
$value = $this->config[$key] ?? $default;
|
||||
|
||||
if (is_bool($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (is_int($value)) {
|
||||
return $value !== 0;
|
||||
}
|
||||
|
||||
if (is_string($value)) {
|
||||
$normalized = strtolower(trim($value));
|
||||
if (in_array($normalized, ['1', 'true', 'yes', 'on'], true)) {
|
||||
return true;
|
||||
}
|
||||
if (in_array($normalized, ['0', 'false', 'no', 'off'], true)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
private function stringList(string $key, array $default): array
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user