百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
F

fast-fuzzy

> 编程语言
开源

快速模糊搜索工具

388 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

快速模糊搜索工具

fast-fuzzy

Fast fuzzy-search utility

methodology

fast-fuzzy is a tiny, lightning-quick fuzzy-searching utility. The ranking algorithm is a modification of levenshtein distance proposed by Peter H. Sellers (paper). fast-fuzzy also uses the damerau-levenshtein distance by default, which, compared to normal levenshtein, punishes transpositions less.

Inputs are normalized before search. Normalization consists of standard utf8-normalization, optionally taking the lowercase of a string, optionally removing non-word characters, and optionally flattening/trimming whitespace. Graphemes, such as conjoined emoji ‍‍‍, are treated as single characters.

Inputs are scored from 0 to 1, where a higher score indicates a closer match. When searching, results are returned in descending order of score. Ties in score are broken by earliness of match (when using sellers substring match only). Further ties are broken by favoring the candidate whose length is closest to the length of the search term. This causes matches which are closer to exact full string matches to be effectively ranked higher. Ties in length difference are broken by insertion order.

Lists of candidates are stored in a trie internally, which avoids doing redundant work on candidates with common prefixes. Additionally, when a subtree of the trie can be determined to have no string which could possibly score >= the threshold, the entire subtree is skipped. This significantly improves search times compared to a bruteforce search.

While the default options are to use Damerau and Sellers (transposition-friendly substring search), either of these options can be opted out of if the need arises.

exports

name description signature
fuzzy fuzzy ranking algorithm; returns match strength (term, candidate, options?) => score
search for one-off searches; returns a sorted array of matches (term, candidates, options?) => matches
Searcher for searching the same set of candidates multiple times; caches the constructed trie1 N/A

1 it is recommended that you use a Searcher when searching the same set multiple times. search will create a new trie every time, and while this is relatively cheap, it can have an impact on responsiveness if you intend to update search results in real time, i.e. while typing.

Searcher methods

name description signature
constructor supply the options and initial list of candidates (candidates?, options?) => searcher
add add new candidates to the list (...candidates) => void
search perform a search against the instance's candidates (term, options?) => matches2

2 allows overriding the threshold, returnMatchData, and useDamerau options

options

Searcher and search both take an options object for configuring behavior.

option type description default
keySelector Function selects the string(s)3 to search when candidates are objects s => s
threshold Number the minimum score that can be returned .6
ignoreCase Bool normalize case by calling toLower on input and pattern true
ignoreSymbols Bool strip non-word symbols4 from input true
normalizeWhitespace Bool normalize and trim whitespace true
returnMatchData Bool return match data5 false
useDamerau Bool use damerau-levenshtein distance true
useSellers Bool use the Sellers method for substring matching true
useSeparatedUnicode Bool use separated unicode false
sortBy sortKind defines which order results are returned in6 bestMatch

3 if the keySelector returns an array, the candidate will take the score of the highest scoring key.

4 `~!@#$%^&*()-=_+{}[]\|\;':",./<>?

5 in the form {item, original, key, score, match: {index, length}}. Match index and length are in terms of the original, non-normalized string. Also note that match will be undefined if useSellers is false.

6 the supported sortKinds are insertOrder and bestMatch

fuzzy accepts a subset of these options (excluding keySelector, threshold, and sortBy) with the same defaults.

examples

You can call fuzzy directly to get a match score for a single string

javascript
const {fuzzy} = require("fast-fuzzy");

fuzzy("hello", "hello world"); //returns 1
fuzzy("word", "hello world"); //returns .75

//pass in custom options
fuzzy("hello world", "hello  world"); //returns 1
fuzzy("hello world", "hello  world", {normalizeWhitespace: false}); //returns .90909090...

Use search to search a list of strings or objects

…

Use Searcher in much the same way as search

…

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言