Tweak doc search algorithm

This commit is contained in:
Griatch 2023-03-02 21:22:01 +01:00
parent 6e7cf07b75
commit d373ec784e

View file

@ -23,37 +23,51 @@ if (!Scorer) {
}, },
*/ */
// Evennia optimized scorer // Evennia optimized scorer
score: function(query, result) { score: function(inquery, result) {
var scorevar = 0; query = inquery.toLowerCase();
if(result[1].startsWith("evennia.")) { var title = result[1].toLowerCase().replace(/<\/?[^>]+(>|$)/g, "");
scorevar = result[4] * 0.8; var score = result[4];
var mscore = score;
if (query === title) {
mscore = score * 10;
}
else if (title.startsWith(query)) {
mscore = score * 8;
if (title.startsWith("evennia.")) {
mscore *= 0.2;
}
}
else if (title.includes(query)) {
mscore = score * 7;
if (title.startsWith("evennia.")) {
mscore *= 0.2;
} }
else if(result[1].toLowerCase().startsWith(query) & query.length == result[1].length) {
scorevar = result[4] * 1.5;
} }
else { else {
scorevar = result[4]; mscore = score * 0.5;
} }
// console.debug("Scored:", result[1], scorevar) // console.log("result: " + title + ", " + score + "->" + mscore);
return scorevar; return mscore;
}, },
// query matches the full name of an object // query matches the full name of an object
objNameMatch: 11, objNameMatch: 3,
// or matches in the last dotted part of the object name // or matches in the last dotted part of the object name
objPartialMatch: 6, objPartialMatch: 2,
// Additive scores depending on the priority of the object // Additive scores depending on the priority of the object
objPrio: {0: 15, // used to be importantResults objPrio: {0: 3, // used to be importantResults
1: 5, // used to be objectResults 1: 2, // used to be objectResults
2: -5}, // used to be unimportantResults 2: -15}, // used to be unimportantResults
// Used when the priority is not in the mapping. // Used when the priority is not in the mapping.
objPrioDefault: 0, objPrioDefault: 0,
// query found in title // query found in title
title: 15, title: 12,
partialTitle: 7, partialTitle: 3,
// query found in terms // query found in terms
term: 5, term: 2,
partialTerm: 2 partialTerm: 1
}; };
} }