feat: improve keyword matching in autoCategorize function to handle short keywords with word boundaries

This commit is contained in:
Julien Froidefond
2025-11-27 10:35:15 +01:00
parent e516ed9efd
commit 2aafce4df0

View File

@@ -141,8 +141,19 @@ export function autoCategorize(description: string, categories: Category[]): str
for (const category of categories) { for (const category of categories) {
for (const keyword of category.keywords) { for (const keyword of category.keywords) {
if (lowerDesc.includes(keyword.toLowerCase())) { const lowerKeyword = keyword.toLowerCase()
return category.id
// 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
}
} }
} }
} }