This commit is contained in:
team 1
2026-04-24 18:54:25 +02:00
parent 372a6797fa
commit c439fb99d6
12 changed files with 1126 additions and 336 deletions

View File

@@ -7,38 +7,12 @@ namespace App\Config;
final readonly class QueryEnricherConfig
{
/**
* Keep the enrichment vocabulary in the class for now.
*
* Important:
* - This is intentionally NOT externalized yet.
* - Add or maintain the current project-specific mappings here.
* - The later move to external config/files can happen separately.
*
* Supported shapes:
*
* 1) Simple mapping:
* [
* 'water hardness' => 'residual hardness',
* 'device' => 'instrument',
* ]
*
* 2) Small synonym groups:
* [
* ['water hardness', 'residual hardness', 'hardness'],
* ['device', 'instrument', 'meter'],
* ]
*
* The public API stays intentionally simple:
* - getEnrichQueryList(): array<string,string>
*
* This keeps QueryEnricher generic while the domain vocabulary
* deliberately remains inside this class for now.
*
* Replace the example entries below with your real project mappings.
* Backwards-compatible fallback vocabulary.
* Active values are loaded from retriex.query_enrichment.config when present.
*
* @var array<int|string, mixed>
*/
private const ENRICH_QUERY_LIST = [
private const DEFAULT_ENRICH_QUERY_LIST = [
'Wasserhärte' => 'Resthärte',
'Gerät' => 'Modell',
'Indikator' => 'Chemie',
@@ -48,9 +22,16 @@ final readonly class QueryEnricherConfig
'Wasserhärte-Grenzwert' => 'Resthärte',
'Resthärte-Grenzwert' => 'Wasserhärte',
'Grenzwert' => 'Überwachungsbereich',
'store'=>'shop'
'store' => 'shop',
];
/**
* @param array<string, mixed> $config
*/
public function __construct(private array $config = [])
{
}
/**
* Returns a normalized, deduplicated mapping for the QueryEnricher.
*
@@ -71,8 +52,13 @@ final readonly class QueryEnricherConfig
public function getEnrichQueryList(): array
{
$normalized = [];
$rules = $this->config['rules'] ?? self::DEFAULT_ENRICH_QUERY_LIST;
foreach (self::ENRICH_QUERY_LIST as $key => $value) {
if (!is_array($rules)) {
$rules = self::DEFAULT_ENRICH_QUERY_LIST;
}
foreach ($rules as $key => $value) {
if (is_array($value)) {
$this->ingestGroup($normalized, $value);
continue;
@@ -93,6 +79,17 @@ final readonly class QueryEnricherConfig
return $normalized;
}
public function getMaxExpansions(): int
{
$value = $this->config['max_expansions'] ?? 4;
if (!is_numeric($value)) {
return 4;
}
return max(0, (int) $value);
}
/**
* Returns true when at least one valid enrichment rule exists.
*/
@@ -176,4 +173,4 @@ final readonly class QueryEnricherConfig
return trim($value);
}
}
}