5dbfbf0049
Moves search things around to match an interface that can be switched in and out of fuzzy searching using fuse.js. We add both fuzzy searching and regex based searching to the codebase here, but it is not yet compiled in.
21 lines
479 B
JavaScript
21 lines
479 B
JavaScript
import Fuse from 'fuse.js';
|
|
|
|
export default class FuzzySearch {
|
|
constructor(items, options) {
|
|
this.fuse = new Fuse(items, {
|
|
includeMatches: true,
|
|
|
|
shouldSort: false, // use our own sorting for the moment
|
|
threshold: 0.4,
|
|
keys: Object.keys(options.finders) || [],
|
|
getFn(item, key) {
|
|
return (options.finders[key[0]](item) || []).toString();
|
|
},
|
|
});
|
|
}
|
|
|
|
search(s) {
|
|
return this.fuse.search(s).map(item => item.item);
|
|
}
|
|
}
|