From 2aafce4df0e651608b62a7e8e496b5f97771c86e Mon Sep 17 00:00:00 2001 From: Julien Froidefond Date: Thu, 27 Nov 2025 10:35:15 +0100 Subject: [PATCH] feat: improve keyword matching in autoCategorize function to handle short keywords with word boundaries --- lib/store-db.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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 + } } } }