fuse.js vs fuzzy vs fuzzy-search vs fuzzyset
模糊搜尋套件
fuse.jsfuzzyfuzzy-searchfuzzyset類似パッケージ:

模糊搜尋套件

模糊搜尋套件在 JavaScript 中提供了對字串進行模糊匹配的功能,這對於搜尋功能、拼寫校正、資料清理等應用非常有用。這些套件允許開發者在搜尋時不必完全匹配字串,而是根據相似度進行匹配,從而提高使用者體驗。fuse.js 是一個輕量且功能強大的模糊搜尋庫,支援多欄位搜尋和自訂權重,適合需要高效且靈活搜尋的應用。fuzzy 提供簡單的模糊匹配功能,適合快速實現基本的模糊搜尋。fuzzy-search 是一個專注於簡單且高效的模糊搜尋庫,適合需要快速搜尋的應用。fuzzyset 則是一個基於集合的模糊匹配庫,適合需要在大量字串中進行高效匹配的應用。

npmのダウンロードトレンド

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
fuse.js19,296,03020,520417 kB214ヶ月前Apache-2.0
fuzzy7,768,643834-2910年前-
fuzzy-search306,07522713 kB01ヶ月前ISC
fuzzyset24,4591,37735.6 kB15年前see LICENSE.md

機能比較: fuse.js vs fuzzy vs fuzzy-search vs fuzzyset

搜尋精度

  • fuse.js:

    fuse.js 提供高度可自訂的搜尋精度,允許設定閾值、權重和多欄位搜尋,適合需要精細調整搜尋結果的應用。

  • fuzzy:

    fuzzy 提供基本的模糊匹配,精度較低,但足以應付簡單的搜尋需求。

  • fuzzy-search:

    fuzzy-search 提供快速且準確的模糊搜尋,特別是在處理小型到中型資料集時表現良好。

  • fuzzyset:

    fuzzyset 使用基於集合的算法,提供高效且準確的匹配,特別適合處理大量字串。

多欄位搜尋

  • fuse.js:

    fuse.js 支援多欄位搜尋,允許為不同欄位設定不同的權重,這使得搜尋結果更加靈活和精確。

  • fuzzy:

    fuzzy 不支援多欄位搜尋,僅限於單一字串的模糊匹配。

  • fuzzy-search:

    fuzzy-search 支援多欄位搜尋,但功能較為簡單,適合需要基本多欄位搜尋的應用。

  • fuzzyset:

    fuzzyset 不支援多欄位搜尋,主要集中在單一集合中的模糊匹配。

性能

  • fuse.js:

    fuse.js 在小型到中型資料集上性能良好,但在處理大型資料集時可能會有性能瓶頸,特別是在使用多欄位和複雜權重設定時。

  • fuzzy:

    fuzzy 性能輕量,適合快速執行簡單的模糊匹配,但不適合處理大量資料。

  • fuzzy-search:

    fuzzy-search 針對性能進行了優化,特別是在處理中型資料集時表現出色,適合需要快速搜尋的應用。

  • fuzzyset:

    fuzzyset 在處理大量字串時性能優越,特別是使用基於集合的算法,適合需要高效搜尋的大型應用。

易用性

  • fuse.js:

    fuse.js 提供直觀的 API 和豐富的文檔,但由於其功能豐富,可能需要一些時間來熟悉和掌握。

  • fuzzy:

    fuzzy 提供簡單易用的 API,適合快速上手和使用。

  • fuzzy-search:

    fuzzy-search 提供簡單且直觀的 API,易於使用,特別是對於需要快速實現模糊搜尋的開發者。

  • fuzzyset:

    fuzzyset 提供簡單的 API,但由於其基於集合的概念,可能需要一些時間來理解其工作原理。

範例程式碼

  • fuse.js:

    fuse.js 範例程式碼

    const Fuse = require('fuse.js');
    const list = [
      { title: 'Old Man's War' },
      { title: 'The Lock Artist' },
      { title: 'HTML5' },
    ];
    const options = {
      keys: ['title'],
      threshold: 0.3,
    };
    const fuse = new Fuse(list, options);
    const result = fuse.search('old man war');
    console.log(result);
    
  • fuzzy:

    fuzzy 範例程式碼

    const fuzzy = require('fuzzy');
    const list = ['apple', 'banana', 'grape', 'orange'];
    const result = fuzzy.filter('aple', list);
    console.log(result);
    
  • fuzzy-search:

    fuzzy-search 範例程式碼

    const FuzzySearch = require('fuzzy-search');
    const list = [
      { name: 'John' },
      { name: 'Jane' },
      { name: 'Jack' },
    ];
    const searcher = new FuzzySearch(list, ['name'], { caseSensitive: false });
    const result = searcher.search('jan');
    console.log(result);
    
  • fuzzyset:

    fuzzyset 範例程式碼

    const FuzzySet = require('fuzzyset.js');
    const set = FuzzySet(['apple', 'banana', 'grape']);
    const result = set.get('aple');
    console.log(result);
    

選び方: fuse.js vs fuzzy vs fuzzy-search vs fuzzyset

  • fuse.js:

    如果你需要一個功能全面且可自訂的模糊搜尋庫,特別是需要多欄位搜尋和權重設定,選擇 fuse.js。它適合需要精細控制搜尋行為的應用。

  • fuzzy:

    如果你只需要簡單的模糊匹配功能,且不需要複雜的設定,選擇 fuzzy。它適合快速實現基本的模糊搜尋功能。

  • fuzzy-search:

    如果你需要一個輕量且高效的模糊搜尋庫,特別是在搜尋速度和資源使用方面有要求,選擇 fuzzy-search。它適合對性能有較高要求的應用。

  • fuzzyset:

    如果你需要在大量字串中進行高效的模糊匹配,特別是需要基於集合的匹配算法,選擇 fuzzyset。它適合處理大規模資料的搜尋應用。

fuse.js のREADME

Fuse.js

Node.js CI Version Downloads code style: prettier Contributors License

Fuse.js is a lightweight, zero-dependency fuzzy-search library written in TypeScript. It works in the browser and on the server, and is designed for searching small-to-medium datasets on the client side where you can't rely on a dedicated search backend.

✨ What's New: Token Search

Multi-word fuzzy search with relevance ranking. Type "javascrpt paterns" and find "JavaScript Patterns" — typo tolerance, multiple words, and smart ranking all at once.

const fuse = new Fuse(docs, {
  useTokenSearch: true,
  keys: ['title', 'author', 'description']
})

fuse.search('javascrpt paterns')
// → [{ item: { title: 'JavaScript Patterns', ... } }]

See Token Search below for details.

Web Workers

Search large datasets without freezing the UI. FuseWorker splits your data across multiple Web Workers and searches in parallel — ~5x faster on 100K documents.

import { FuseWorker } from 'fuse.js/worker'

const fuse = new FuseWorker(docs, {
  keys: ['title', 'author', 'description']
})

const results = await fuse.search('query')
fuse.terminate()

Same options and results as Fuse — just async. Function-valued options (sortFn, getFn, keys[].getFn) aren't supported because functions can't be transferred to a worker; everything else carries over. See the Web Workers docs for the interactive demo and full API.

Installation

npm install fuse.js
yarn add fuse.js

Or include directly via CDN:

<script src="https://cdn.jsdelivr.net/npm/fuse.js/dist/fuse.min.mjs"></script>

Quick Start

import Fuse from 'fuse.js'

const books = [
  { title: "Old Man's War", author: 'John Scalzi' },
  { title: 'The Lock Artist', author: 'Steve Hamilton' },
  { title: 'HTML5', author: 'Remy Sharp' },
  { title: 'JavaScript: The Good Parts', author: 'Douglas Crockford' }
]

const fuse = new Fuse(books, {
  keys: ['title', 'author']
})

fuse.search('javscript')
// → [{ item: { title: 'JavaScript: The Good Parts', ... }, ... }]

Features

Fuzzy Search

The core of Fuse.js. Uses the Bitap algorithm for approximate string matching — handles typos, misspellings, and partial matches out of the box.

fuse.search('javscript')
// → [{ item: { title: 'JavaScript: The Good Parts', author: 'Douglas Crockford' } }]

Weighted Keys

Search across multiple fields with different importance levels. Title matches can rank higher than description matches.

const fuse = new Fuse(docs, {
  keys: [
    { name: 'title', weight: 2 },
    { name: 'description', weight: 1 }
  ]
})

Extended Search

Use operators for precise control: exact match (=), prefix (^), suffix (!), and more. Enable with useExtendedSearch: true.

const fuse = new Fuse(list, {
  useExtendedSearch: true,
  keys: ['title']
})

fuse.search('=exact match')   // exact match
fuse.search('^prefix')        // starts with
fuse.search('!term')          // does not include

Token Search

Splits multi-word queries into individual terms, fuzzy-matches each independently, and ranks results using BM25-style IDF weighting. Enable with useTokenSearch: true.

const fuse = new Fuse(docs, {
  useTokenSearch: true,
  keys: ['title', 'body']
})

fuse.search('express midleware rout')
// Finds "Express Middleware" and "Express Routing Guide" despite typos
  • Typo tolerance per word — each term is fuzzy-matched independently
  • Relevance ranking — rare terms are weighted higher than common ones
  • Word order independent — "patterns javascript" and "javascript patterns" return identical results
  • No query length limit — long multi-word queries work naturally since each term is searched separately
  • AND or OR — tokenMatch: 'all' returns only records matching every word (filtering); the default 'any' matches any word
  • Custom tokenizer — pass a regex or function via tokenize for tokens with internal punctuation (node.js, c++), or use Intl.Segmenter for CJK / Thai word segmentation. Unicode-aware by default

Available in the full build. See the Token Search docs for details and performance benchmarks.

Logical Search

Combine conditions with $and and $or for complex queries. Available in the full build.

fuse.search({
  $and: [
    { title: 'javascript' },
    { author: 'crockford' }
  ]
})

Match Highlighting

Get character-level match indices for highlighting search results in your UI.

const fuse = new Fuse(list, {
  includeMatches: true,
  keys: ['title']
})

const result = fuse.search('javscript')
// result[0].matches[0].indices → [[0, 9]]

Single String Matching

Use Fuse.match() to fuzzy-match a pattern against a single string without creating an index. Useful for one-off comparisons or custom filtering.

const result = Fuse.match('javscript', 'JavaScript: The Good Parts')
// → { isMatch: true, score: 0.04, indices: [[0, 9]] }

Fuse.match() does not support useTokenSearch — token search requires corpus-level statistics (df, fieldCount) that a one-off string comparison can't provide. Passing useTokenSearch: true throws an explicit error. Use new Fuse(docs, { useTokenSearch: true }).search(query) for token-search behavior.

Dynamic Collections

Add and remove documents from a live index without rebuilding.

fuse.add({ title: 'New Book', author: 'New Author' })
fuse.remove((doc) => doc.title === 'Old Book')

Builds

Fuse.js ships in two variants:

BuildIncludesMin + gzip
FullFuzzy + Extended + Logical + Token search~8.6 kB
BasicFuzzy search only~6.8 kB

Use the basic build if you only need fuzzy search and want the smallest bundle size.

Documentation

For the full API reference, configuration options, scoring theory, and interactive demos, visit fusejs.io.

Official ports

  • fuse-swift: Swift port for iOS, macOS, tvOS, watchOS, visionOS, and Linux. Byte-equivalent results, idiomatic Swift API, syncs with each upstream release. Currently in 2.0.0-rc.1.

Supporting Fuse.js

Develop

See DEVELOPERS.md for setup, scripts, and project structure.

Contribute

See CONTRIBUTING.md for guidelines on issues and pull requests.