it didn't suggest the best result
See original GitHub issuewith a List like this
const list = [
{label:'exhibit motorcar engine v11'},
{label:'exhibit motorcar engine v10'},
{label:'exhibit motorcar engine v12'},
{label:'selling motorcar engine fly over v15'}
]
const searchWord = 'engine v15'
const options = {
isCaseSensitive: false,
keys: ['label'],
}
const fuse = new Fuse(list, options)
const result = fuse.search(searchWord)
console.log(result)
[
{label:'exhibit motorcar engine v11'},
{label:'exhibit motorcar engine v10'},
{label:'exhibit motorcar engine v12'},
{label:'selling motorcar engine fly over v15'}
]
What I got back is that exact order. Which is not correct, the item with keyword engine
and v15
should be on the top score. If search result consists of 100 item, the selling motorcar engine fly over v15
will be about at the bottom of the result. Which is totally wrong. Because selling motorcar engine fly over v15
is most relevant to search term engine v15
.
I was expecting the result below, which is more accurate.
[
{label:'selling motorcar engine fly over v15'},
{label:'exhibit motorcar engine v11'},
{label:'exhibit motorcar engine v10'},
{label:'exhibit motorcar engine v12'}
]
Issue Analytics
- State:
- Created 2 years ago
- Comments:23 (4 by maintainers)
Top Results From Across the Web
Help improve Google search results
Things that are confusing or don't work; Suggestions for making Google Search better. Be as specific as you can. More info helps us...
Read more >Why Feedback Rarely Does What It's Meant To
What we mean by “feedback” is very different. Feedback is about telling people what we think of their performance and how they should...
Read more >Why Facts Don't Change Our Minds | The New Yorker
They cite research suggesting that people experience genuine pleasure—a rush of dopamine—when processing information that supports their beliefs ...
Read more >Use Search on your iPhone, iPad, or iPod touch - Apple Support
Search also offers suggestions and updates results as you type. ... Show on Home Screen, Suggest App, or Suggest Notifications.
Read more >Optimism (for Teens) - Nemours KidsHealth
The good news is, even pessimists can be more optimistic. ... Because they don't view setbacks as personal failings, optimists are able to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@zehawki, re:
Fuse.js was designed with two things in mind: simplicity and performance. It consequently, by design, does not have sufficiently advanced search capabilities for fields with large text. Internally it uses a modified Bitap algorithm, which is an approximate string matching algorithm, and tells whether a given text contains a substring that is “approximately equal” to a given pattern, where approximate equality is defined in terms of Levenshtein distance. if the text and pattern are within a given distance k of each other, then the algorithm considers them equal. [wiki]
I would argue that in order to search in large text and have a better relevance score, there are additional algorithms that Fuse.js would have to incorporate, such as tf-idf. This would produce a “fairer” score relative to the length of text. But doing this would considerably bloat the library.
(Note: at some point though, I may add plugin capabilities, so that Fuse.js could be expanded)
Nonetheless, for those times that users want to search large text, you can always update
location
,distance
and/orthreshold
. Modifying these, at the very least, still allows for the calculation of the distance, and therefore produces a “truer” score. Conversely, simply settingignoreLocation
totrue
bypasses the distance calculation.@zehawki I’m looking at the example you provided, this isn’t a bug.
Please check out the scoring theory 😄
The list you provided:
Since you didn’t specify the fuzzy-matching options, Fuse.js will use the following values:
location
defaults to0
distance
defaults to100
threshold
defaults to0.6
With the above options, for something to be considered a match, it would have to be within (threshold)
0.6
x (distance)100
=60
characters away from the expected location0
.But taking each of the search queries (patterns) you provided above:
URL
is found at index 77needed
is found at index 144unless
is found at index 130really needed
is found at index 137developers
is found at index 147Each of those patterns appears more than
60
characters away, therefore they wouldn’t match anything.If you don’t care where the pattern appears in the string, and you still want to consider it a match, set
ignoreLocation
totrue
.