Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
source: (answers, input) => {
const fuse = new Fuse(ELEMENT_OPTIONS, { keys: ['name'] })
return new Promise((res,rej) => {
// fuzzy search the elements
if (input) {
const result = fuse.search(input)
res(result)
}
res(ELEMENT_OPTIONS)
})
}
},
return new Promise(resolve => {
/* fuse likes objects */
const historyMap = history.map(h => ({ command: h }))
const options = { keys: ['command'] }
const fuse = new Fuse(historyMap, options)
const matchingHistory = fuse.search(hint)
let choices = unique(matchingHistory.map(h => h.command))
choices = choices.filter((c) => c);
if (!choices.length) resolve(history)
else resolve(choices)
})
}
function searchListing(fileSet, opt_searchQuery) {
if (!opt_searchQuery) {
return fileSet;
}
// Fuzzy find from the file set
const fuse = new Fuse(fileSet, {
shouldSort: true,
threshold: 0.4,
});
return fuse.search(opt_searchQuery).map(i => fileSet[i]);
}
const fuzzySearchBestMatch = (items, needle, optionalTargetProperties) => {
let options = fuzzySearchOptions;
if (optionalTargetProperties) {
options = Object.assign({}, options);
options.keys = optionalTargetProperties;
}
let cleanNeedle = needle
.trim()
.replace(/^of /gi, '');
let fuse = new Fuse(items, options);
let searchResult = fuse.search(cleanNeedle);
if (searchResult.length === 0) {
throw new Error(`No fuzzy match for '${cleanNeedle}'`);
}
let bestMatch = searchResult[0];
console.log(`best fuzzy match for '${cleanNeedle}' is:`, bestMatch);
return Promise.resolve(bestMatch);
};
React.useEffect(() => {
fuseRef.current = new Fuse(options, fuseOptions)
const computed = getMatchedOptions(searchText, options, fuseRef.current, maxDisplayedOptions)
setMatchedOptions(computed)
}, [options.length, searchText])
onKeywordChanged(): void {
if (this.searchKeyword === '') {
this.displayedRepos = [...this.repos];
return;
}
const options = {
keys: ['name', 'full_name', 'repository_provider', 'description', 'html_url'] as any[],
id: 'id'
};
this.fuse = new Fuse(this.repos, options);
const ids = this.fuse.search(this.searchKeyword).map(id => Number(id));
this.displayedRepos = this.repos.filter(repo => ids.indexOf(Number(repo.id)) !== -1);
}
}
public constructor(init: PatternSearchInit) {
this.fuse = new Fuse(init.patterns.map(item => item.toJSON()), {
keys: ['name', 'description']
});
}
run(function*(gen) {
try {
var tracks = yield getLibrary(gen());
tracks = tracks.filter((track) => {
return (typeof track.storeId === 'undefined');
});
var fuse = new Fuse(tracks, FUSE_OPTIONS);
tracks = fuse.search(q);
callback(null, tracks.slice(0, 50));
} catch (err) {
callback(err);
}
});
};
findMatches(query){
const fuse = new Fuse(this.options, {
keys: ['title', 'key']
});
var fragment = query.toLowerCase();
var options = fuse.search(query);
for (var i = 0; i < options.length; i++){
options[i].holder = this.holder;
options[i].grammar = this.grammars[options[i].key];
}
return options;
}
}
findMatches(query){
const fuse = new Fuse(this.options, {
keys: ['title', 'grammar.key']
});
var fragment = query.toLowerCase();
return fuse.search(query);
/*
return this.options.filter(x => {
return x.lower.search(fragment) > -1;
});
*/
}
}