admin管理员组文章数量:1393326
I was trying to implement fuse.js to my app where I have array of strings without any key.
['Kelly', 'Creed', 'Stanley', 'Oscar', 'Michael', 'Jim', 'Darryl', 'Phyllis', 'Pam', 'Dwight', 'Angela', 'Andy', 'William', 'Ryan', 'Toby', 'Bob']
When I try to configure the fuse.js I'm getting no results, because of unspecified key.
var options = {
shouldSort: true,
threshold: 0.6,
location: 0,
distance: 100,
maxPatternLength: 32,
minMatchCharLength: 1,
keys: [
"title",
"author.firstName"
]
};
var fuse = new Fuse(list, options); // "list" is the item array
var result = fuse.search("");
is it possible to perform fuzzy search on plain array, or do I need to convert everything to be an object?
I was trying to implement fuse.js to my app where I have array of strings without any key.
['Kelly', 'Creed', 'Stanley', 'Oscar', 'Michael', 'Jim', 'Darryl', 'Phyllis', 'Pam', 'Dwight', 'Angela', 'Andy', 'William', 'Ryan', 'Toby', 'Bob']
When I try to configure the fuse.js I'm getting no results, because of unspecified key.
var options = {
shouldSort: true,
threshold: 0.6,
location: 0,
distance: 100,
maxPatternLength: 32,
minMatchCharLength: 1,
keys: [
"title",
"author.firstName"
]
};
var fuse = new Fuse(list, options); // "list" is the item array
var result = fuse.search("");
is it possible to perform fuzzy search on plain array, or do I need to convert everything to be an object?
Share Improve this question asked Dec 4, 2019 at 14:42 Lukáš VáclavekLukáš Václavek 4521 gold badge6 silver badges12 bronze badges1 Answer
Reset to default 5It's possible to do a search on an array of strings. You need to not specify a keys
property in the options object.
Here's an example:
const list = ['Kelly', 'Creed', 'Stanley'];
// your options can be anything you want, but don't include
// the keys property
let options = {
shouldSort: true,
threshold: 0.6,
location: 0,
distance: 100,
maxPatternLength: 32,
minMatchCharLength: 1,
// don't include the keys property
};
const fuse = new Fuse(list, options);
let result = fuse.search('Kelly');
// result will be:
// {"item":"Kelly","refIndex":0}
// here, refIndex is the index of the element in list
本文标签: javascriptFusejs search in array of stringsStack Overflow
版权声明:本文标题:javascript - Fuse.js search in array of strings - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744628267a2616387.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论