diff --git a/lib/store-db.ts b/lib/store-db.ts index b0b32c6..25589c3 100644 --- a/lib/store-db.ts +++ b/lib/store-db.ts @@ -141,8 +141,19 @@ export function autoCategorize(description: string, categories: Category[]): str for (const category of categories) { for (const keyword of category.keywords) { - if (lowerDesc.includes(keyword.toLowerCase())) { - return category.id + const lowerKeyword = keyword.toLowerCase() + + // Pour les keywords courts (< 4 chars), matcher uniquement des mots entiers + if (lowerKeyword.length < 4) { + const wordBoundary = new RegExp(`\\b${lowerKeyword}\\b`) + if (wordBoundary.test(lowerDesc)) { + return category.id + } + } else { + // Pour les keywords plus longs, includes() suffit + if (lowerDesc.includes(lowerKeyword)) { + return category.id + } } } }