fuseJS 模糊搜索对我不起作用
fuseJS fuzzy search is not working for me
有没有 fuseJS 专家可以告诉我为什么 fuseJS 模糊搜索不适合我,我认为它应该。 (请参阅下面的演示代码。)当我搜索 "presets" 时,我得到一个返回结果,即:
预设 ... eDirectory ... 2018/5/30 17:22:50 ... 4 KB
但是当我搜索 "sets" 时,我没有返回任何结果。我不应该为这两个搜索获得相同的结果吗?我需要在选项中添加一些东西吗?或者这种类型的搜索不能用 fuseJS 实现吗?
在此先感谢您能给我的任何帮助。
P.M.
<!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>
看看threshold
(摘自http://fusejs.io/)
Threshold
At what point does the match algorithm give up. A threshold of 0.0
requires a perfect match (of both letters and location), a threshold of 1.0
would match anything.
例如,并将值更改为 0.2
。然后你得到一个结果。
您可以尝试使用更多数据集为 threshold
设置一些不同的值并检查结果。
var 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" }],
searchString = "sets",
options = { keys: ['name', 'type', "dateModified", "size"], threshold: 0.2, caseSensitive: false },
f = new Fuse(files, options),
output = f.search(searchString),
i;
document.getElementById("searchString").innerHTML = searchString;
document.getElementById("json").value = JSON.stringify(files);
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 src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/3.0.4/fuse.min.js"></script>
<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>
有没有 fuseJS 专家可以告诉我为什么 fuseJS 模糊搜索不适合我,我认为它应该。 (请参阅下面的演示代码。)当我搜索 "presets" 时,我得到一个返回结果,即:
预设 ... eDirectory ... 2018/5/30 17:22:50 ... 4 KB
但是当我搜索 "sets" 时,我没有返回任何结果。我不应该为这两个搜索获得相同的结果吗?我需要在选项中添加一些东西吗?或者这种类型的搜索不能用 fuseJS 实现吗?
在此先感谢您能给我的任何帮助。
P.M.
<!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>
看看threshold
(摘自http://fusejs.io/)
例如,Threshold
At what point does the match algorithm give up. A threshold of
0.0
requires a perfect match (of both letters and location), a threshold of1.0
would match anything.
并将值更改为 0.2
。然后你得到一个结果。
您可以尝试使用更多数据集为 threshold
设置一些不同的值并检查结果。
var 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" }],
searchString = "sets",
options = { keys: ['name', 'type', "dateModified", "size"], threshold: 0.2, caseSensitive: false },
f = new Fuse(files, options),
output = f.search(searchString),
i;
document.getElementById("searchString").innerHTML = searchString;
document.getElementById("json").value = JSON.stringify(files);
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 src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/3.0.4/fuse.min.js"></script>
<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>