fuse.js vs fuzzy-search vs fuzzyset
フロントエンドにおけるファジー検索ライブラリの選定
fuse.jsfuzzy-searchfuzzyset類似パッケージ:

フロントエンドにおけるファジー検索ライブラリの選定

fuse.js、fuzzy-search、fuzzyset はすべて JavaScript 環境で曖昧検索(ファジー検索)を実現するライブラリですが、メンテナンス状況、API 設計、そして想定されるユースケースに大きな違いがあります。fuse.js は現在も活発に開発されており、高度な設定やオブジェクト検索に対応しています。一方、fuzzy-search と fuzzyset は長期間更新されておらず、新規プロジェクトでの採用には技術的負債のリスクが伴います。特に fuzzyset は文字列の集合に対するマッチングに特化しており、他の 2 つとは用途が異なります。

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

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
fuse.js20,797,44920,535417 kB274ヶ月前Apache-2.0
fuzzy-search301,12822713 kB02ヶ月前ISC
fuzzyset29,1471,37835.6 kB15年前see LICENSE.md

フロントエンドにおけるファジー検索:fuse.js vs fuzzy-search vs fuzzyset

ユーザー入力への柔軟な対応や、スペルミスを許容した検索機能を実装する際、JavaScript 製のファジー検索ライブラリは重要な役割を果たします。fuse.js、fuzzy-search、fuzzyset はいずれもこの目的で使われますが、内部のアルゴリズム、メンテナンス状況、そして API の設計思想に明確な違いがあります。本記事では、アーキテクトの視点からこれらを比較し、プロジェクトに適した選択ができるよう解説します。

🛠️ メンテナンス状況とエコシステム

ライブラリ選定において、メンテナンス状況は機能以上に重要です。バグ修正やセキュリティ対応、新しい JavaScript 仕様への追随が行われているか確認する必要があります。

fuse.js は現在も活発に開発が続いています。

  • 定期的にリリースが行われ、バグ修正や機能改善が加えられています。
  • TypeScript の型定義が公式に提供されており、大規模プロジェクトでも安心です。
// fuse.js: 最新の API で利用可能
import Fuse from 'fuse.js';
// 活発なメンテナンスにより、最新の JS 機能にも対応

fuzzy-search は事実上の開発終了状態です。

  • 最終更新から数年が経過しており、新しい機能追加は見込めません。
  • 既存プロジェクトの維持以外での使用は推奨されません。
// fuzzy-search: 長期間更新なし
import FuzzySearch from 'fuzzy-search';
// 新規プロジェクトでの使用はリスクを伴います

fuzzyset も同様にメンテナンスが停止しています。

  • 非常に軽量ですが、アルゴリズムの改善やバグ修正は期待できません。
  • 特殊なユースケース以外では、代替ライブラリの検討が必要です。
// fuzzyset: メンテナンス停止
import fuzzyset from 'fuzzyset';
// 長期運用には適さない可能性があります

🔌 API 設計と設定の柔軟性

検索対象のデータ構造や、検索精度の調整方法もライブラリごとに異なります。特にオブジェクト配列を扱う場合、設定のしやすさが開発効率に直結します。

fuse.js は高度な設定オプションを提供します。

  • 検索対象のキー(key)ごとに重み付けが可能です。
  • 閾値(threshold)を調整して、検索の厳しさを制御できます。
// fuse.js: 詳細な設定が可能
const fuse = new Fuse(list, {
  keys: ['title', 'author'],
  threshold: 0.3,
  includeScore: true
});
const result = fuse.search('pattern');

fuzzy-search は設定がシンプルです。

  • キーの指定はできますが、重み付けなどの細かな制御はできません。
  • 小規模なリスト検索には十分ですが、複雑な要件には向きません。
// fuzzy-search: シンプルな設定
const searcher = new FuzzySearch(list, ['title', 'author']);
const result = searcher.search('pattern');
// 重み付けなどの詳細設定はできません

fuzzyset は文字列の集合を扱います。

  • オブジェクト配列ではなく、文字列の配列を前提としています。
  • 検索というより、入力に対するベストマッチの取得に適しています。
// fuzzyset: 文字列集合が対象
const set = fuzzyset(['apple', 'banana', 'orange']);
const result = set.get('aple'); 
// [[score, 'apple']] のような形式で返ります

📤 検索結果の返却形式

検索結果をどのように受け取るかも、UI 実装に大きな影響を与えます。スコア情報の有無や、データ構造の違いに注意してください。

fuse.js は豊富なメタデータを返します。

  • 一致したアイテムだけでなく、スコアや一致したインデックス情報も得られます。
  • 結果の並び替えや、ハイライト表示に役立ちます。
// fuse.js: 詳細な結果オブジェクト
/*
[
  {
    item: { title: 'Apple' },
    score: 0.1,
    refIndex: 0
  }
]
*/

fuzzy-search はマッチしたアイテムのみを返します。

  • 結果は単純な配列であり、スコア情報は含まれません。
  • 単純なリスト表示には使いやすいですが、精度の可視化は困難です。
// fuzzy-search: マッチしたアイテムの配列
/*
[
  { title: 'Apple' },
  { title: 'Pineapple' }
]
*/

fuzzyset はスコアとペアで返します。

  • 配列の中に [スコア,アイテム] の形式で返却されます。
  • 最も近い候補を 1 つだけ取得したい場合に適しています。
// fuzzyset: スコアとアイテムのペア
/*
[
  [0.9, 'apple'],
  [0.5, 'grape']
]
*/

📊 比較サマリー

特徴fuse.jsfuzzy-searchfuzzyset
メンテナンス✅ 活発❌ 停止❌ 停止
検索対象オブジェクト配列オブジェクト配列文字列配列
設定項目豊富(重み・閾値)最小限なし
結果形式オブジェクト(スコア込)アイテム配列スコアとアイテムのペア
TypeScript✅ 公式対応❌ 社区定義❌ 社区定義

💡 最終的な推奨事項

fuse.js は、現代のフロントエンド開発における標準的な選択です — 機能性、メンテナンス性、コミュニティの規模すべてにおいて優れています。新規プロジェクトでは、特別な理由がない限りこれ一択です。

fuzzy-search と fuzzyset は、既存のレガシーシステムを維持する場合や、極めて単純なスクリプト内で依存関係を増やしたくない場合に限って検討してください。ただし、長期的な視点では fuse.js への移行を計画すべきです。

検索機能はユーザー体験に直結する重要な要素です。信頼性が高く、柔軟なライブラリを選ぶことが、結果的に開発コストの削減と品質の向上につながります。

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

  • fuse.js:

    新規プロジェクトでは常に fuse.js を第一選択としてください。メンテナンスが活発で、型定義(TypeScript)も充実しており、重み付けやインデックス機能など高度な検索設定が可能です。コミュニティも大きく、問題発生時の解決策が見つかりやすいのも利点です。

  • fuzzy-search:

    既存のレガシーコードを維持する場合のみ検討します。API はシンプルですが、長期間更新されていないため、セキュリティやバグ修正の保証がありません。新規採用は避けるべきです。

  • fuzzyset:

    文字列の補正や、単純な文字列集合からのベストマッチ取得など特殊な用途に限られます。こちらもメンテナンス停止状態のため、可能であれば fuse.js などの代替案を検討してください。

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.