mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-09-05 01:15:04 +00:00
Support multiple partial matches
This commit is contained in:
@@ -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()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user