feat: improve keyword matching in autoCategorize function to handle short keywords with word boundaries
This commit is contained in:
@@ -141,9 +141,20 @@ 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()
|
||||||
|
|
||||||
|
// 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
|
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