From 8deca97f1c709c2e155310082ef101cbdd774633 Mon Sep 17 00:00:00 2001 From: Ilya Boyazitov Date: Sat, 27 Apr 2024 11:16:29 +0000 Subject: [PATCH] fix search term match and highlight for unicode chars --- src/assets/javascripts/sphinx_search.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/assets/javascripts/sphinx_search.ts b/src/assets/javascripts/sphinx_search.ts index 98404fd7c..427daf28a 100644 --- a/src/assets/javascripts/sphinx_search.ts +++ b/src/assets/javascripts/sphinx_search.ts @@ -724,7 +724,7 @@ export async function getResults(query: string): Promise { // The search term made be made up of multiple "words" separated // by special characters like [-._]. Split them up and treat each // as a separate search term. - for (const wordMatch of lowerTerm.matchAll(/\w+/g)) { + for (const wordMatch of lowerTerm.matchAll(/\p{L}+/gu)) { const subTerm = wordMatch[0] if (stopwords.indexOf(subTerm) !== -1) { // skip this "word" @@ -794,8 +794,8 @@ export async function getResults(query: string): Promise { } const pattern = new RegExp( - `\\b(?:${ hlterms.map(escapeRegExp).join("|") })`, - "img" + `(?:${ hlterms.map(escapeRegExp).join("|") })`, + "imgu" ) const highlight = (s: unknown) => { return `${s}` @@ -803,7 +803,7 @@ export async function getResults(query: string): Promise { const highlightTerms = (text: string) => { return escapeHTML(text) .replace(pattern, highlight) - .replace(/<\/mark>(\s+)]*>/gim, "$1") + .replace(/<\/mark>(\s+)]*>/gimu, "$1") } return {