central config part 2
This commit is contained in:
@@ -6,10 +6,67 @@ namespace App\Config;
|
||||
|
||||
final class SearchRepairConfig
|
||||
{
|
||||
private const GENERIC_CANDIDATE_TOKENS = [
|
||||
'wasser',
|
||||
'messgerät',
|
||||
'messgeraet',
|
||||
'produkt',
|
||||
'geräte',
|
||||
'geraete',
|
||||
'gerät',
|
||||
'geraet',
|
||||
'resthärte',
|
||||
'resthaerte',
|
||||
'preis',
|
||||
'infos',
|
||||
'wissen',
|
||||
];
|
||||
|
||||
private const ACCESSORY_CANDIDATE_TERMS = [
|
||||
'indikator',
|
||||
'indicator',
|
||||
'reagenz',
|
||||
'reagent',
|
||||
'kit',
|
||||
'set',
|
||||
];
|
||||
|
||||
private const ACCESSORY_OR_BUNDLE_TERMS = [
|
||||
'passend',
|
||||
'passende',
|
||||
'zubehor',
|
||||
'zubehör',
|
||||
'dazu',
|
||||
'zusatz',
|
||||
'erganzung',
|
||||
'ergänzung',
|
||||
'indikator',
|
||||
'reagenz',
|
||||
'kit',
|
||||
'set',
|
||||
'auch\s+das',
|
||||
'mit\s+preis\s+und\s+allen\s+infos',
|
||||
];
|
||||
|
||||
private const SPECIFICITY_BOOST_TERMS = [
|
||||
'indikator',
|
||||
'indicator',
|
||||
'testomat',
|
||||
'tritromat',
|
||||
'titromat',
|
||||
'reagenz',
|
||||
'reagent',
|
||||
];
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $config
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly bool $enabled = true,
|
||||
private readonly int $maxRepairQueries = 3,
|
||||
private readonly int $minPrimaryResultsWithoutRepair = 2,
|
||||
private readonly array $config = [],
|
||||
private readonly ?DomainVocabularyConfig $vocabulary = null,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -58,26 +115,13 @@ final class SearchRepairConfig
|
||||
return '/\b(?:' . implode('|', $this->getSpecificityBoostTerms()) . ')\b/iu';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
/** @return string[] */
|
||||
public function getGenericCandidateTokens(): array
|
||||
{
|
||||
return [
|
||||
'wasser',
|
||||
'messgerät',
|
||||
'messgeraet',
|
||||
'produkt',
|
||||
'geräte',
|
||||
'geraete',
|
||||
'gerät',
|
||||
'geraet',
|
||||
'resthärte',
|
||||
'resthaerte',
|
||||
'preis',
|
||||
'infos',
|
||||
'wissen',
|
||||
];
|
||||
return $this->stringList(
|
||||
'generic_candidate_tokens',
|
||||
$this->vocabularyView('search_repair.generic_candidate_tokens', self::GENERIC_CANDIDATE_TOKENS)
|
||||
);
|
||||
}
|
||||
|
||||
public function getSanitizeTrimCharacters(): string
|
||||
@@ -155,57 +199,61 @@ final class SearchRepairConfig
|
||||
return 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
/** @return string[] */
|
||||
public function getAccessoryCandidateTerms(): array
|
||||
{
|
||||
return [
|
||||
'indikator',
|
||||
'indicator',
|
||||
'reagenz',
|
||||
'reagent',
|
||||
'kit',
|
||||
'set',
|
||||
];
|
||||
return $this->stringList(
|
||||
'accessory_candidate_terms',
|
||||
$this->vocabularyView('search_repair.accessory_candidate_terms', self::ACCESSORY_CANDIDATE_TERMS)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
/** @return string[] */
|
||||
public function getAccessoryOrBundleTerms(): array
|
||||
{
|
||||
return [
|
||||
'passend',
|
||||
'passende',
|
||||
'zubehor',
|
||||
'zubehör',
|
||||
'dazu',
|
||||
'zusatz',
|
||||
'erganzung',
|
||||
'ergänzung',
|
||||
'indikator',
|
||||
'reagenz',
|
||||
'kit',
|
||||
'set',
|
||||
'auch\s+das',
|
||||
'mit\s+preis\s+und\s+allen\s+infos',
|
||||
];
|
||||
return $this->stringList(
|
||||
'accessory_or_bundle_terms',
|
||||
$this->vocabularyView('search_repair.accessory_or_bundle_terms', self::ACCESSORY_OR_BUNDLE_TERMS)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
/** @return string[] */
|
||||
public function getSpecificityBoostTerms(): array
|
||||
{
|
||||
return [
|
||||
'indikator',
|
||||
'indicator',
|
||||
'testomat',
|
||||
'tritromat',
|
||||
'titromat',
|
||||
'reagenz',
|
||||
'reagent',
|
||||
];
|
||||
return $this->stringList(
|
||||
'specificity_boost_terms',
|
||||
$this->vocabularyView('search_repair.specificity_boost_terms', self::SPECIFICITY_BOOST_TERMS)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
private function vocabularyView(string $path, array $fallback): array
|
||||
{
|
||||
return $this->vocabulary?->view($path, $fallback) ?? $fallback;
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
private function stringList(string $key, array $default): array
|
||||
{
|
||||
$value = $this->config[$key] ?? $default;
|
||||
if (!is_array($value)) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
$out = [];
|
||||
foreach ($value as $item) {
|
||||
if (!is_scalar($item)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$item = trim((string) $item);
|
||||
if ($item === '' || in_array($item, $out, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$out[] = $item;
|
||||
}
|
||||
|
||||
return $out !== [] ? $out : $default;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user