(search) use lookarounds to simulate word boundary which works for non-latin scripts

This commit is contained in:
Valentyne Stigloher 2024-12-20 13:19:46 +01:00
parent 3034fbe209
commit 6a576b6c7a

View File

@ -105,7 +105,9 @@ const getTermsByField = (matches: MatchInfo): Record<string, string[]> => {
const FRAGMENT_MAX_WORDCOUNT = 24;
const highlightMatches = (field: string, terms: string[] | undefined, fragment: boolean = false): string => {
const termsRegex = terms && terms.length > 0 ? new RegExp(`\\b(${terms.join('|')})\\b`, 'ig') : undefined;
const termsRegex = terms && terms.length > 0
? new RegExp(`(?<!\\p{L}|\\p{N})(${terms.join('|')})(?!\\p{L}|\\p{N})`, 'iug')
: undefined;
if (fragment) {
const words = field.split(' ');