fuse.js vs lunr vs flexsearch vs js-search vs search-index vs elasticlunr
JavaScript 搜尋庫
fuse.jslunrflexsearchjs-searchsearch-indexelasticlunr類似套件:

JavaScript 搜尋庫

這些搜尋庫提供了在客戶端或伺服器端進行高效能的文本搜尋功能。它們各自具有不同的特性和優勢,適用於不同的搜尋需求和場景。這些庫可以幫助開發者快速實現搜尋功能,並提升用戶體驗。

npm下載趨勢

3 年

GitHub Stars 排名

統計詳情

套件
下載數
Stars
大小
Issues
發布時間
許可
fuse.js20,262,76720,534417 kB264 個月前Apache-2.0
lunr9,480,4009,202-1306 年前MIT
flexsearch1,288,66613,8242.33 MB401 年前Apache-2.0
js-search166,5802,212117 kB84 年前MIT
search-index54,1371,421722 kB113 個月前MIT
elasticlunr26,6162,064-7710 年前MIT

功能比較: fuse.js vs lunr vs flexsearch vs js-search vs search-index vs elasticlunr

性能

  • fuse.js:

    fuse.js 在處理小型數據集時表現良好,但在大型數據集上可能會出現性能瓶頸。

  • lunr:

    lunr 提供了良好的搜尋性能,能夠處理中型數據集,並且支持自定義的搜尋邏輯。

  • flexsearch:

    flexsearch 是目前性能最佳的搜尋庫之一,能夠在大量數據中進行快速搜尋,並且支持多種索引策略以提高效能。

  • js-search:

    js-search 提供了基本的搜尋性能,適合小型應用程式,但在處理大量數據時可能會變得緩慢。

  • search-index:

    search-index 提供了可擴展的搜尋性能,能夠處理大量數據並支持分佈式搜尋。

  • elasticlunr:

    elasticlunr 提供了快速的搜尋性能,適合小型數據集。由於其輕量級的設計,對於靜態網站來說非常合適。

模糊搜尋

  • fuse.js:

    fuse.js 專注於模糊搜尋,能夠根據用戶輸入的部分字串返回相關結果,並支持權重設置。

  • lunr:

    lunr 支持基本的模糊搜尋,但不如 flexsearch 和 fuse.js 強大,適合一般用途。

  • flexsearch:

    flexsearch 提供了強大的模糊搜尋功能,能夠處理拼寫錯誤和相似詞,適合需要高精度搜尋的應用。

  • js-search:

    js-search 不支持模糊搜尋,主要用於精確匹配,適合簡單的搜尋需求。

  • search-index:

    search-index 提供了基本的模糊搜尋功能,能夠滿足大多數搜尋需求。

  • elasticlunr:

    elasticlunr 支持基本的模糊搜尋,但功能較為簡單,適合不需要複雜搜尋的場景。

易用性

  • fuse.js:

    fuse.js 的 API 非常直觀,易於使用,適合快速實現模糊搜尋功能。

  • lunr:

    lunr 的 API 也相對簡單,但需要了解一些索引和搜尋的基本概念。

  • flexsearch:

    flexsearch 的配置選項較多,可能需要一些學習曲線,但提供了靈活的搜尋功能。

  • js-search:

    js-search 的 API 簡單明瞭,適合初學者和小型項目,快速實現基本搜尋。

  • search-index:

    search-index 的 API 可能較為複雜,適合有經驗的開發者使用。

  • elasticlunr:

    elasticlunr 的 API 簡單易用,適合初學者快速上手,並且有良好的文檔支持。

擴展性

  • fuse.js:

    fuse.js 的擴展性較低,主要用於模糊搜尋,功能相對固定。

  • lunr:

    lunr 支持自定義的搜尋邏輯和分詞器,適合需要擴展的中型項目。

  • flexsearch:

    flexsearch 提供了多種索引選項和配置,能夠靈活應對不同的搜尋需求,具有很高的擴展性。

  • js-search:

    js-search 的擴展性有限,主要適合簡單的搜尋需求,不適合複雜的應用。

  • search-index:

    search-index 提供了良好的擴展性,支持持久化存儲和分佈式搜尋,適合大型應用。

  • elasticlunr:

    elasticlunr 支持自定義分詞器和擴展功能,適合需要特定搜尋需求的項目。

社群支持

  • fuse.js:

    fuse.js 擁有良好的社群支持,並且有許多範例和教程可供參考。

  • lunr:

    lunr 擁有穩定的社群支持,並且有良好的文檔和範例。

  • flexsearch:

    flexsearch 也有活躍的社群,並且不斷更新,提供了豐富的範例和文檔。

  • js-search:

    js-search 的社群相對較小,但仍然有基本的文檔和範例可供使用。

  • search-index:

    search-index 的社群支持較為活躍,並且有許多範例和教程可供參考。

  • elasticlunr:

    elasticlunr 擁有活躍的社群和良好的文檔支持,適合初學者學習和使用。

如何選擇: fuse.js vs lunr vs flexsearch vs js-search vs search-index vs elasticlunr

  • fuse.js:

    選擇 fuse.js 如果你需要模糊搜尋功能。它非常適合用於小型數據集,並且支持權重和優先級設置,能夠提供更靈活的搜尋結果。

  • lunr:

    選擇 lunr 如果你需要一個功能強大的全文搜尋引擎,並且希望能夠在客戶端進行索引和搜尋。它支持多語言和自定義的分詞器,適合中型到大型項目。

  • flexsearch:

    選擇 flexsearch 如果你需要極高的搜尋性能和靈活性。它提供了多種索引選項和配置,並且能夠處理大量數據,適合需要快速搜尋的應用程式。

  • js-search:

    選擇 js-search 如果你需要一個簡單易用的搜尋庫,並且希望能夠快速實現基本的搜尋功能。它的 API 簡單,適合初學者和小型項目。

  • search-index:

    選擇 search-index 如果你需要一個可擴展的搜尋解決方案,並且希望能夠在 Node.js 環境中使用。它支持持久化存儲和分佈式搜尋,適合需要高可用性的應用程式。

  • elasticlunr:

    選擇 elasticlunr 如果你需要一個輕量級的搜尋解決方案,並且希望能夠在客戶端進行索引和搜尋。它支持多語言和自定義的分詞器,非常適合小型項目或靜態網站。

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.