有没有 fuseJS 专家可以告诉我为什么 fuseJS 模糊搜索不适合我,因为我认为它应该。(请参阅下面的演示代码。)当我搜索“预设”时,我得到一个返回结果,即:
预设 ... eDirectory ... 2018/5/30 17:22:50 ... 4 KB
但是当我搜索“集合”时,我没有得到任何结果。我不应该为这两个搜索获得相同的结果吗?我需要在选项中添加一些东西吗?或者 fuseJS 无法进行这种类型的搜索?
提前感谢您能给我的任何帮助。
下午
<!DOCTYPE html>
<html lang="en">
<head>
<title>Fuse.js example</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/3.0.4/fuse.min.js"></script>
</head>
<body>
<h2>data:</h2>
<textarea id="json" cols="30" rows="10"></textarea>
<h2>Search for: <span id="searchString"></span></h2>
<h2>Results:</h2>
<div id="results"></div>
<script>
files =[
{
name: "zips",
type: "bDirectory",
dateModified: "2018/5/10 17:39:27",
size: "1 KB"
}
,
{
name: "presets",
type: "eDirectory",
dateModified: "2018/5/30 17:22:50",
size: "4 KB"
}
,
{
name: "workflow",
type: "dDirectory",
dateModified: "2018/6/11 7:23:11",
size: "5 KB"
}
,
{
name: "software",
type: "aDirectory",
dateModified: "2018/6/14 14:35:36",
size: "2 KB"
}
,
{
name: "nmm_data",
type: "fDirectory",
dateModified: "2018/6/14 15:37:08",
size: "6 KB"
}
,
{
name: "jobs",
type: "cDirectory",
dateModified: "2018/6/15 13:43:47",
size: "3 KB"
}
];
var searchString = "presets";
document.getElementById("searchString").innerHTML = searchString;
document.getElementById("json").value=JSON.stringify(files);
var options = {
keys: ['name','type', "dateModified", "size"],
threshold:0.0,
caseSensitive:false
}
var f = new Fuse(files, options);
var output = f.search(searchString);
console.log(output);
for(i=0;i<output.length;i++){
document.getElementById('results').innerHTML += output[i].name + ' ... ' + output[i].type + ' ... ' + output[i].dateModified + ' ... ' + output[i].size + '<br />'
}
</script>
</body>
</html>