fix(receipt-import): route egg items away from allergy dairy

This commit is contained in:
Nils-Johan Gynther
2026-05-02 20:32:50 +02:00
parent d9113bb89a
commit 6733a50cfb
@@ -515,6 +515,28 @@ export class ReceiptImportService {
if (fallbackHit) return fallbackHit; if (fallbackHit) return fallbackHit;
} }
// ── Regel: Ägg (saknar egen L2/L3 i nuvarande träd) ────────────────
const hasEggSignal =
/\bagg\b/.test(normalized) ||
/\begg\b/.test(normalized) ||
/\binne\b/.test(normalized) ||
/\b24p\b/.test(normalized);
if (hasEggSignal) {
const l1DairyEgg = categories.find(
(c) => c.path.toLowerCase() === 'mejeri, ost & ägg',
);
if (l1DairyEgg) {
return {
categoryId: l1DairyEgg.id,
categoryName: l1DairyEgg.name,
path: l1DairyEgg.path,
confidence: 'high',
usedFallback: false,
};
}
}
// ── Regel: Te ──────────────────────────────────────────────────────── // ── Regel: Te ────────────────────────────────────────────────────────
const isTea = const isTea =
/\bte\b/.test(normalized) || /\bte\b/.test(normalized) ||
@@ -693,6 +715,30 @@ export class ReceiptImportService {
} }
} }
const hasEggSignal =
/\bagg\b/.test(normalized) ||
/\begg\b/.test(normalized) ||
/\binne\b/.test(normalized) ||
/\b24p\b/.test(normalized);
if (hasEggSignal && suggestion.path.toLowerCase().includes('allergi mejeri')) {
const l1DairyEgg = categories.find(
(c) => c.path.toLowerCase() === 'mejeri, ost & ägg',
);
if (l1DairyEgg) {
this.logger.log(
`AI contradiction-guard: "${rawName}" remappas från "${suggestion.path}" till "${l1DairyEgg.path}"`,
);
return {
categoryId: l1DairyEgg.id,
categoryName: l1DairyEgg.name,
path: l1DairyEgg.path,
confidence: 'high',
usedFallback: true,
};
}
}
const hasCreamSignal = const hasCreamSignal =
/\bvispgradde\b/.test(normalized) || /\bvispgradde\b/.test(normalized) ||
/\bmatlagningsgradde\b/.test(normalized) || /\bmatlagningsgradde\b/.test(normalized) ||