在Fuse,js中,为什么在文档说应该忽略阈值设置时更改阈值,结果也会改变?

时间:2019-04-09 06:26:02

标签: fuse.js

当文档说: 当(Tokenize为true)为true时,该算法将搜索单个单词和整个字符串,并根据这两个函数计算最终分数。 在这种情况下,阈值,距离和位置对于单个令牌都无关紧要,因此被忽略

如果更改阈值,则会得到不同的结果!

使用https://fusejs.io/上的标准示例并设置以下选项:

var options = {
  shouldSort: true,
  tokenize: true,
  matchAllTokens: true,
  includeScore: true,
  threshold: 0,
  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("Lost");

以上内容只会给您一个匹配条件:

[
   {
    "item": {
      "title": "The Lost Symbol",
      "author": {
        "firstName": "Dan",
        "lastName": "Brown"
      }
    },
    "score": 0.5
  }
  ]

现在将阈值更改为1,结果将更改为:

[
  {
    "item": {
      "title": "The Lost Symbol",
      "author": {
        "firstName": "Dan",
        "lastName": "Brown"
      }
    },
    "score": 0.27
  },
  {
   "item": {
      "title": "The Lock Artist",
      "author": {
        "firstName": "Steve",
        "lastName": "Hamilton"
      }
    },
    "score": 0.2825
  }, 

...还有更多!

更改阈值时,我不希望对结果集进行任何更改。有人有解释吗?

0 个答案:

没有答案