Fixed search when query contains colon after non-field

This commit is contained in:
squidfunk 2023-01-28 14:01:02 +01:00
parent 148c9fdba4
commit a6436bd483
4 changed files with 27 additions and 13 deletions

View File

@ -212,7 +212,7 @@
"base": base_url,
"features": features,
"translations": {},
"search": "assets/javascripts/workers/search.e5c33ebb.min.js" | url
"search": "assets/javascripts/workers/search.db81ec45.min.js" | url
} -%}
{%- if config.extra.version -%}
{%- set _ = app.update({ "version": config.extra.version }) -%}

View File

@ -70,14 +70,28 @@ export function transformSearchQuery(
/* Extract and tokenize term from lexeme */
for (const { type, str: term, start, end } of lexer.lexemes)
if (type === "TERM")
split(term, lunr.tokenizer.separator, (...range) => {
terms.push([
part.slice(0, start),
term.slice(...range),
part.slice(end)
].join(""))
})
switch (type) {
/* Hack: remove colon - see https://bit.ly/3wD3T3I */
case "FIELD":
if (!["title", "text", "tags"].includes(term))
part = [
part.slice(0, end),
" ",
part.slice(end + 1)
].join("")
break
/* Tokenize term */
case "TERM":
split(term, lunr.tokenizer.separator, (...range) => {
terms.push([
part.slice(0, start),
term.slice(...range),
part.slice(end)
].join(""))
})
}
/* Return terms */
return terms