1
0
mirror of https://github.com/nextapps-de/flexsearch.git synced 2025-09-25 12:58:59 +02:00

fix result highlighting #489

This commit is contained in:
Thomas Wilkerling
2025-04-17 10:09:16 +02:00
parent dafb137153
commit b75cccb0f8
26 changed files with 171 additions and 87 deletions

View File

@@ -516,7 +516,7 @@ function highlight_fields(query, result, index, pluck, template) {
// prefix
doc_org_cur.substring(0, position) +
// match
template.replace("$1", doc_org_cur.substring(position, query_enc_cur.length)) +
template.replace("$1", doc_org_cur.substring(position, position + query_enc_cur.length)) +
// suffix
doc_org_cur.substring(position + query_enc_cur.length);
found = !0;

View File

@@ -16,7 +16,9 @@ export const filter = new Set(["a", "about", "above", "after", "again", "against
//"hell",
"her", "here", "heres", "hers", "herself", "hes", "him", "himself", "his", "how", "hows", "i", "id", "if", "ill", "im", "in", "into", "is", "isnt", "it", "its", "itself", "ive", "just", "know", "lets", "like",
//"look",
"lot", "make", "made", "me", "more", "most", "mustnt", "my", "myself", "new", "no", "nor", "not", "now", "of", "off", "on", "once", "one", "only", "or", "other", "ought", "our", "ours", "ourselves", "out", "over", "own", "people", "same", "say", "see", "shant", "she", "shed", "shell", "shes", "should", "shouldnt", "so", "some", "such", "take", "than", "that", "thats", "the", "their", "theirs", "them", "themselves", "then", "there", "theres", "these", "they", "theyd", "theyll", "theyre", "theyve", "think", "this", "those", "through", "time", "times", "to", "too",
"lot", "make", "made", "me", "more", "most", "mustnt", "my", "myself", "new", "no", "nor", "not", "now", "of", "off", "on", "once", "one", "only", "or", "other", "ought", "our", "ours", "ourselves", "out", "over", "own",
//"people",
"same", "say", "see", "shant", "she", "shed", "shell", "shes", "should", "shouldnt", "so", "some", "such", "take", "than", "that", "thats", "the", "their", "theirs", "them", "themselves", "then", "there", "theres", "these", "they", "theyd", "theyll", "theyre", "theyve", "think", "this", "those", "through", "time", "times", "to", "too",
//"two",
"under", "until", "up", "us", "use", "very", "want", "was", "wasnt", "way", "we", "wed", "well", "were", "werent", "weve", "what", "whats", "when", "whens", "where", "wheres", "which", "while", "who", "whom", "whos", "why", "whys", "will", "with", "wont", "work", "would", "wouldnt",
//"year",
@@ -26,7 +28,26 @@ export const filter = new Set(["a", "about", "above", "after", "again", "against
* @type {Map<string, string>}
*/
export const stemmer = new Map([["ational", ""], ["iveness", ""], ["fulness", ""], ["ousness", ""], ["ization", ""], ["tional", "tion"], ["biliti", ""], ["icate", ""], ["ative", ""], ["alize", ""], ["iciti", ""], ["entli", ""], ["ousli", ""], ["alism", ""], ["ation", ""], ["aliti", ""], ["iviti", ""], ["ement", ""], ["izer", ""], ["able", ""], ["ible", ""], ["alli", ""], ["ator", ""], ["less", ""], ["logi", ""], ["ical", ""], ["ance", ""], ["ence", ""], ["ness", ""], ["ble", ""], ["ment", ""], ["eli", ""], ["bli", ""], ["ful", ""], ["ant", ""], ["ent", ""], ["ism", ""], ["ate", ""], ["iti", ""], ["ous", ""], ["ive", ""], ["ize", ""], ["ing", ""], ["ion", ""], ["ies", "y"], ["al", ""], ["ou", ""], ["er", ""], ["ed", ""], ["es", "e"], ["ic", ""], ["ly", ""], ["li", ""], ["s", ""]]);
export const stemmer = new Map([
//["ational", "ate"],
//["iveness", ""],
//["fulness", ""],
//["ousness", ""],
["ization", ""],
//["tional", "tion"],
["biliti", ""], ["icate", ""], ["ative", ""],
//["alize", ""],
//["iciti", ""],
//["entli", ""],
//["ousli", ""],
//["alism", ""],
["ation", ""],
//["aliti", ""],
["iviti", ""], ["ement", ""], ["izer", ""], ["able", ""], ["ible", ""], ["alli", ""], ["ator", ""], ["less", ""], ["logi", ""], ["ical", ""], ["ance", ""], ["ence", ""], ["ness", ""], ["ble", ""], ["ment", ""],
//["nal", "n"],
["eli", ""], ["bli", ""], ["ful", ""], ["ant", ""], ["ent", ""], ["ism", ""], ["ate", ""], ["iti", ""], ["ous", ""], ["ive", ""], ["ize", ""], ["ing", ""], ["ion", ""], ["ies", "y"], ["al", ""], ["ou", ""], ["er", ""], ["ed", ""],
//["es", "e"],
["ic", ""], ["ly", ""], ["li", ""], ["s", ""]]);
/*
hes (= he is / he has)
@@ -63,7 +84,9 @@ const options = {
prepare: function (str) {
return str
// normalize symbols
.replace(/´`ʼ/g, "'").replace(/_+/g, " ").replace(/&/g, " and ").replace(/\$/g, " USD ").replace(/£/g, " GBP ")
.replace(/´`ʼ/g, "'")
//.replace(/[_\-]+/g, " ")
.replace(/&/g, " and ").replace(/\$/g, " USD ").replace(/£/g, " GBP ")
// explode short forms
.replace(/\bi'm\b/g, "i am").replace(/\b(can't|cannot)\b/g, "can not").replace(/\bwon't\b/g, "will not").replace(/([a-z])'s\b/g, "$1 is has").replace(/([a-z])n't\b/g, "$1 not").replace(/([a-z])'ll\b/g, "$1 will").replace(/([a-z])'re\b/g, "$1 are").replace(/([a-z])'ve\b/g, "$1 have").replace(/([a-z])'d\b/g, "$1 would had");
},