From c115f83879dc792697ecdd5922a571e9474a7bad Mon Sep 17 00:00:00 2001 From: dadaloop82 Date: Sun, 19 Apr 2026 09:07:44 +0000 Subject: [PATCH] fix(bring): avoid ambiguous fallback match on generic words like 'dolce' - italianToBring(): pass-2 whole-word fallback now ignores generic qualifiers (dolce, light, classico, originale, etc.) - when multiple single-word matches exist, choose the longest/specific token instead of first catalog iteration hit - prevents wrong mappings like 'Pancetta Dolce' being interpreted via generic adjective rather than the core product token --- api/index.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/api/index.php b/api/index.php index c2e6222..a77dfad 100644 --- a/api/index.php +++ b/api/index.php @@ -2811,18 +2811,32 @@ function italianToBring(string $italianName): string { // Uses word-boundary logic (split on spaces) to avoid substring false positives like // "gin" inside "original", "rum" inside "crumble", "aceto" inside "pancetta", etc. // Only considers single-word catalog keys (multi-word keys need Pass 1 exact match). + // To avoid ambiguous mappings (e.g. "pancetta dolce" => "mais"), skip generic qualifiers + // and pick the most specific (longest) matching token. $inputWords = array_filter( preg_split('/\s+/', $lower), fn($w) => mb_strlen($w) >= 4 // skip very short words — too ambiguous ); + + $genericQualifiers = [ + 'dolce','salato','light','bio','classico','original','naturale','fresco','fresca', + 'intero','intera','magro','magra','piccolo','piccola','grande','rosso','bianco' + ]; + $candidates = []; foreach ($catalog['it2de'] as $itLower => $deKey) { if (str_contains($itLower, ' ')) continue; // multi-word key → exact-only if (mb_strlen($itLower) < 4) continue; // too short → skip (gin, rum, etc.) + if (in_array($itLower, $genericQualifiers, true)) continue; if (in_array($itLower, $inputWords, true)) { - return $deKey; + $candidates[] = ['it' => $itLower, 'de' => $deKey, 'len' => mb_strlen($itLower)]; } } + if (!empty($candidates)) { + usort($candidates, fn($a, $b) => $b['len'] <=> $a['len']); + return $candidates[0]['de']; + } + // No match — return the original Italian name so Bring! shows it as a custom item return $italianName; }