Support multiple partial matches

This commit is contained in:
shamoon
2026-06-16 15:50:44 -07:00
parent 3e7b0a873a
commit a4c3953210
2 changed files with 11 additions and 1 deletions
+7
View File
@@ -7,4 +7,11 @@ describe('text search utilities', () => {
expect(matchesSearchText('\u0152uvre', 'oeuvre')).toBeTruthy()
expect(matchesSearchText('Invoice', 'receipt')).toBeFalsy()
})
it('matches all whitespace-separated search terms independently', () => {
expect(matchesSearchText('taxes 2026', 'tax 26')).toBeTruthy()
expect(matchesSearchText('2026 taxes', 'tax 26')).toBeTruthy()
expect(matchesSearchText('Tax\u00e9s 2026', 'taxe 26')).toBeTruthy()
expect(matchesSearchText('taxes 2026', 'tax receipt')).toBeFalsy()
})
})
+4 -1
View File
@@ -8,5 +8,8 @@ export function matchesSearchText(
value: unknown,
searchText: unknown
): boolean {
return normalizeSearchText(value).includes(normalizeSearchText(searchText))
const normalizedValue = normalizeSearchText(value)
const searchTerms = normalizeSearchText(searchText).trim().split(/\s+/)
return searchTerms.every((term) => normalizedValue.includes(term))
}