Closed loucadufault closed 4 years ago
The matched indices don't have any association with "match score". The code for telling whether a character is matched looks basically like this:
const query = "old";
const text = "old new borrowed blue";
const queryChars = new Set([...query]);
for (let char of text) {
if (queryChars.has(char)) {
// it's a match
}
}
It's useful for highlighting, but really doesn't correspond to an actual "match". According to your ranking algorithm, a search for "faxts" would give a higher score to "ssss" than "facts".
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days
The issue here is that when a result is returned with the option includeMatches:true, I would expect that in any one of the results, the matches of that result would be ordered by relevance, or highest fraction of matched characters over total chars. I would expect to simply access the most relevant match by doing:
(the last line of code (
var match = ...
is what I am referring to)Because of this I find myself having to create logic to iterate through each match, tally up the indices of matched characters in
matches[i]["indices"]
for each match in each result and divide by thematch.length
to get a matchScore. Then select the match with the highest score. This is a good 40 lines of code, especially with the complex array structure of the indices.Would really be great if this could be done by Fuse itself, possibly as an option. The current behaviour is to sort by
["arrayIndex"]
, which seems like a completely arbitrary decision.