好用的字符串搜索库 - Fuse.js

发布时间 2023-04-19 09:00:14作者: 一路向北√

https://github.com/krisk/Fuse

 

Options

#Basic Options

#isCaseSensitive

  • Type: boolean
  • Default: false

Indicates whether comparisons should be case sensitive.

#includeScore

  • Type: boolean
  • Default: false

Whether the score should be included in the result set. A score of 0indicates a perfect match, while a score of 1 indicates a complete mismatch.
分数是否应包括在结果中。分数为0表示完全匹配,而分数为1表示完全不匹配。

#includeMatches

  • Type: boolean
  • Default: false

Whether the matches should be included in the result set. When true, each record in the result set will include the indices of the matched characters. These can consequently be used for highlighting purposes.
匹配的内容是否应该包括在结果中。当为真时,结果集中的每条记录都将包括匹配字符的索引。因此,这些可以用于突出显示的目的。

#minMatchCharLength

  • Type: number
  • Default: 1

Only the matches whose length exceeds this value will be returned. (For instance, if you want to ignore single character matches in the result, set it to 2).
只有长度超过这个值的匹配才会被返回。(例如,如果你想在结果中忽略单字符匹配,将其设置为2)。

#shouldSort

  • Type: boolean
  • Default: true

Whether to sort the result list, by score.
是否对结果列表进行排序,按分数排序。

#findAllMatches

  • Type: boolean
  • Default: false

When true, the matching function will continue to the end of a search pattern even if a perfect match has already been located in the string.

当为 "true "时,即使在字符串中已经找到了完美匹配,匹配功能也会继续到搜索模式的末端。

#keys

  • Type: Array
  • Default: []

List of keys that will be searched. This supports nested paths, weighted search, searching in arrays of strings and objects.
将被搜索的键的列表。这支持嵌套路径,加权搜索,在字符串和对象的数组中搜索。

#Fuzzy Matching Options

#location

  • Type: number
  • Default: 0

Determines approximately where in the text is the pattern expected to be found.
确定在文本中预期找到的模式的大约位置。

#threshold

  • Type: number
  • Default: 0.6

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.0的阈值要求完全匹配(字母和位置),1.0的阈值将匹配任何东西。

#distance

  • Type: number
  • Default: 100

Determines how close the match must be to the fuzzy location (specified by location). An exact letter match which is distance characters away from the fuzzy location would score as a complete mismatch. A distance of 0 requires the match be at the exact location specified. A distance of 1000 would require a perfect match to be within 800 characters of the location to be found using a threshold of 0.8.
决定匹配必须与模糊位置(由位置指定)有多近。一个精确的字母匹配,如果离模糊位置有一定的距离,将被视为完全不匹配。如果距离为0,则需要在指定的确切位置进行匹配。如果距离为1000,则需要在800个字符内找到一个完全匹配的位置,使用0.8的阈值。

#ignoreLocation

  • Type: boolean
  • Default: false

When true, search will ignore location and distance, so it won't matter where in the string the pattern appears.
当为 "true "时,搜索将忽略位置和距离,所以图案出现在字符串的哪个位置并不重要。

TIP

The default options only search the first 60 characters. This should suffice if it is reasonably expected that the match is within this range. To modify this behavior, set the appropriate combination of locationthresholddistance (or ignoreLocation).
默认选项只搜索前60个字符。如果可以合理地预期匹配在这个范围内,这就足够了。要修改这种行为,请设置适当的位置、阈值、距离(或忽略位置)的组合。

To better understand how these options work together, read our Scoring Theory.

#Advanced Options  高级选项

#useExtendedSearch

  • Type: boolean
  • Default: false

When true, it enables the use of unix-like search commands. See example.
当为 "true "时,它可以启用类似unix的搜索命令。请看例子。

#getFn

  • Type: Function
  • Default: (obj: T, path: string | string[]) => string | string[]

The function to use to retrieve an object's value at the provided path. The default will also search nested paths.

用来检索对象在提供的路径上的值的函数。默认情况下,也会搜索嵌套的路径。

#sortFn

  • Type: Function
  • Default: (a, b) => number

The function to use to sort all the results. The default will sort by ascending relevance score, ascending index.
用来对所有结果进行排序的函数。默认情况下,将按相关性分数升序排序,指数升序排序。

#ignoreFieldNorm

  • Type: boolean
  • Default: false

When true, the calculation for the relevance score (used for sorting) will ignore the field-length norm.
当为真时,相关性分数的计算(用于排序)将忽略字段长度规范。

TIP

The only time it makes sense to set ignoreFieldNorm to true is when it does not matter how many terms there are, but only that the query term exists.

唯一将ignoreFieldNorm设置为 "true "有意义的是,当有多少个术语,而只是查询术语存在时,这并不重要。

#fieldNormWeight

  • Type: number
  • Default: 1

Determines how much the field-length norm affects scoring. A value of 0 is equivalent to ignoring the field-length norm. A value of 0.5 will greatly reduce the effect of field-length norm, while a value of 2.0 will greatly increase it.
决定字段长度规范对评分的影响程度。0的值相当于忽略了字段长度规范。0.5的值将大大降低场长规范的影响,而2.0的值将大大增加它。