krisk / Fuse

Lightweight fuzzy-search, in JavaScript
https://fusejs.io/
Apache License 2.0
18.05k stars 766 forks source link

Scores for nested lists #447

Closed ushypocrites closed 4 years ago

ushypocrites commented 4 years ago

Hi I have this nested list that am trying on the fuse.js website, I was wondering if it's possible to have a score per match in the list if options includematches=true? The below example returns just one score per document, not per included matches in the 'programs' nested list. Thanks!

Also even though I set a threshold=0.4 I do get results with scores above that. Would like to know why and more explanation of what the resulting scores are. Thanks!

List to search: [ { name: 'University of Waterloo', programs: [ { key: 1, name: 'Life Physics (Optional Co-op)', }, { key: 2, name: 'Physics and Astronomy (Optional Co-op)', } ] }, { key: 2, name: 'University of Saskatchewan', programs: [ { key: 1, name: 'Engineering Physics', }, { key: 2, name: 'Mathematical Physics', }, { key: 3, name: 'Computer Science', } ]
} ]

const options = { // isCaseSensitive: false, includeScore: true, shouldSort: true, includeMatches: true, findAllMatches: true, // minMatchCharLength: 1, // location: 0, threshold: 0.4, // distance: 100, // useExtendedSearch: false, ignoreLocation: true, // ignoreFieldNorm: false, keys: [ "programs.name" ] }; const fuse = new Fuse(list, options);

// Change the pattern const pattern = "co-op"

return fuse.search(pattern)

[ { "item": { "name": "University of Waterloo", "programs": [ { "key": 1, "name": "Life Physics (Optional Co-op)" }, { "key": 2, "name": "Physics and Astronomy (Optional Co-op)" } ] }, "refIndex": 0, "matches": [ { "indices": [ [ 0, 0 ], [ 5, 5 ], [ 16, 16 ], [ 18, 18 ], [ 23, 24 ], [ 27, 27 ], [ 32, 36 ] ], "value": "Physics and Astronomy (Optional Co-op)", "key": "programs.name", "refIndex": 1 }, { "indices": [ [ 5, 5 ], [ 10, 10 ], [ 14, 15 ], [ 18, 18 ], [ 23, 27 ] ], "value": "Life Physics (Optional Co-op)", "key": "programs.name", "refIndex": 0 } ], "score": 0.0014421153515248686 }, { "item": { "key": 2, "name": "University of Saskatchewan", "programs": [ { "key": 1, "name": "Engineering Physics" }, { "key": 2, "name": "Mathematical Physics" }, { "key": 3, "name": "Computer Science" } ] }, "refIndex": 1, "matches": [ { "indices": [ [ 0, 1 ], [ 3, 3 ], [ 10, 10 ], [ 14, 14 ] ], "value": "Computer Science", "key": "programs.name", "refIndex": 2 } ], "score": 0.5231863610884103 } ]

krisk commented 4 years ago

I was wondering if it's possible to have a score per match in the list if options includematches=true?

I've been debating this. Will circle back with an update about this.

Also even though I set a threshold=0.4 I do get results with scores above that. Would like to know why and more explanation of what the resulting scores are. Thanks!

The threshold is used for filtering on the fuzziness score, which is internally calculated. The final score is a relevance score, and thus a combination of other factors. Take a look at Fuse.js score theory 😄

github-actions[bot] commented 4 years ago

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