Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search multiple words while ignoring the word order in Fuse (Javascript fuzzy search)

how can i match multiple words in fuse while ignoring anything in between and also ignoring the word-order?

for the following example (pseudo-code) the algorithm should match the all items in the possibleResults-array for the search-term team lead.

const options = {}
const possibleResults = ['lead', 'team lead', 'lead of software development team']
const fuse = new Fuse(possibleResults, options)
fuse.search('team lead')

i've tried it with the following options:

{
threshold: 0, // the lower the more exact
ignoreLocation: true, // ignores how "far" result is
findAllMatches: true,
};

but without success. as far as i know Fuse now always sets tokenize: true per default. so that's not helping ...

like image 265
Peter Piper Avatar asked Sep 15 '25 04:09

Peter Piper


1 Answers

one solution i'll leave here just in case someone else stumbles across the same issue is:

const options = {useExtendedSearch: true}    
const adaptedSearchTerm = 'team lead'.split(' ').reduce((previousValue, currentValue) => previousValue + ` '${currentValue}`, '');
fuse.search(adaptedSearchTerm)

which makes use of the extended-search feature of fuse by adding ' in front of every splitted search-term.

like image 58
Peter Piper Avatar answered Sep 17 '25 18:09

Peter Piper