Skip to content

Commit

Permalink
fix search term match and highlight for unicode chars
Browse files Browse the repository at this point in the history
  • Loading branch information
Bizordec committed Nov 19, 2024
1 parent d32b12a commit bad2190
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/assets/javascripts/sphinx_search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ export async function getResults(query: string): Promise<SearchResultStream> {
// 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"
Expand Down Expand Up @@ -794,16 +794,16 @@ export async function getResults(query: string): Promise<SearchResultStream> {
}

const pattern = new RegExp(
`\\b(?:${ hlterms.map(escapeRegExp).join("|") })`,
"img"
`(?:${ hlterms.map(escapeRegExp).join("|") })`,
"imgu"
)
const highlight = (s: unknown) => {
return `<mark data-md-highlight>${s}</mark>`
}
const highlightTerms = (text: string) => {
return escapeHTML(text)
.replace(pattern, highlight)
.replace(/<\/mark>(\s+)<mark[^>]*>/gim, "$1")
.replace(/<\/mark>(\s+)<mark[^>]*>/gimu, "$1")
}

return {
Expand Down

0 comments on commit bad2190

Please sign in to comment.