feat: Enhance apple categorization logic and improve bulk category update feedback
Test Suite / test (24.15.0) (push) Has been cancelled
Test Suite / test (24.15.0) (push) Has been cancelled
This commit is contained in:
@@ -144,6 +144,13 @@ Regler:
|
||||
throw new ServiceUnavailableException('MISTRAL_API_KEY är inte konfigurerad i miljövariabler');
|
||||
}
|
||||
|
||||
// Snabb deterministic guard för välkända äppelsorter.
|
||||
// Detta minskar felklassning när "äpple" saknas i namnet (t.ex. Granny Smith).
|
||||
const appleCategory = this.matchAppleVarietyCategory(productName, categories);
|
||||
if (appleCategory) {
|
||||
return appleCategory;
|
||||
}
|
||||
|
||||
const categoryList = categories
|
||||
.map((c) => `[${c.id}] ${c.path}`)
|
||||
.join('\n');
|
||||
@@ -156,6 +163,7 @@ ${categoryList}
|
||||
KWICK-MATCHNING (gör detta först):
|
||||
- Kött/fläsk: Sök efter ord som "fläsk", "flaskytterfile", "bacon", "kotlett", "karré" → Kött, chark & fågel > Fläsk
|
||||
- Fågel: Sök efter "kyckling", "kalkon", "drumstick", "filé" → Kött, chark & fågel > Fågel
|
||||
- Äpplen/fruktsorter: Sök efter "äpple", "apple", "granny smith", "pink lady", "royal gala", "golden delicious", "jonagold", "fuji" → Frukt & Grönt > Frukt > Äpplen (eller Frukt om Äpplen saknas)
|
||||
- Choklad/spreads: Sök efter "nutella", "choklad", "kakao", "spreads" → Sötsaker & snacks > Choklad & spreads
|
||||
- Bröd: Sök efter "bröd", "toast", "brödrost", "limpa" → Bröd & bakvaror > Bröd
|
||||
|
||||
@@ -288,4 +296,45 @@ Regler:
|
||||
usedFallback: true,
|
||||
};
|
||||
}
|
||||
|
||||
private matchAppleVarietyCategory(
|
||||
productName: string,
|
||||
categories: FlatCategory[],
|
||||
): CategorySuggestion | null {
|
||||
const normalized = productName.trim().toLowerCase();
|
||||
const looksLikeApple = /\b(äpple|apple|granny\s*smith|pink\s*lady|royal\s*gala|golden\s*delicious|jonagold|fuji|braeburn|aroma)\b/i
|
||||
.test(normalized);
|
||||
|
||||
if (!looksLikeApple) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const appleLeaf = categories.find(
|
||||
(c) => c.path.toLowerCase() === 'frukt & grönt > frukt > äpplen',
|
||||
);
|
||||
if (appleLeaf) {
|
||||
return {
|
||||
categoryId: appleLeaf.id,
|
||||
categoryName: appleLeaf.name,
|
||||
path: appleLeaf.path,
|
||||
confidence: 'high',
|
||||
usedFallback: false,
|
||||
};
|
||||
}
|
||||
|
||||
const fruitFallback = categories.find(
|
||||
(c) => c.path.toLowerCase() === 'frukt & grönt > frukt',
|
||||
);
|
||||
if (fruitFallback) {
|
||||
return {
|
||||
categoryId: fruitFallback.id,
|
||||
categoryName: fruitFallback.name,
|
||||
path: fruitFallback.path,
|
||||
confidence: 'high',
|
||||
usedFallback: false,
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user