feat: improve keyword matching in autoCategorize function to handle short keywords with word boundaries
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user