fuse.js vs fuzzy vs fuzzy-search vs fuzzyset
クライアントサイド検索ライブラリの選定基準
fuse.jsfuzzyfuzzy-searchfuzzyset類似パッケージ:

クライアントサイド検索ライブラリの選定基準

fuse.js、fuzzy、fuzzy-search、fuzzyset はすべて JavaScript 環境で近似文字列検索(ファジー検索)を実現するライブラリです。ユーザーの入力ミスに強い検索ボックス、コマンドパレット、データフィルタリングなど、検索 UX を向上させるために使われます。それぞれアルゴリズムの仕組み、設定の柔軟性、メンテナンス状況に違いがあります。

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、fuzzy、fuzzy-search、fuzzyset はこの課題を解決する代表的なライブラリですが、内部構造と適性が異なります。実務での選定に役立つよう、技術的な違いを比較します。

🎯 アルゴリズムと精度:重み付け vs 単純マッチ

検索の精度は、ユーザー体験に直結します。各ライブラリは異なるアルゴリズムを採用しています。

fuse.js は Bitap アルゴリズムをベースにしつつ、フィールドごとの重み付けや閾値調整が可能です。

  • 検索結果にスコアが付与され、精度の高い順に並べられます。
  • 設定オプションが豊富で、細かい挙動制御ができます。
// fuse.js: 重み付け検索
const fuse = new Fuse(list, {
  keys: ['title', 'author'],
  threshold: 0.3
});
const result = fuse.search('query');
// result: [{ item: {...}, score: 0.15 }, ...]

fuzzy は単純なパターンマッチングを行います。

  • 文字列間の類似度をスコア化しますが、重み付け機能はありません。
  • ハイライト表示用のレンダリング結果を返すのが特徴です。
// fuzzy: 単純マッチ
const result = fuzzy.match('candidate string', 'pattern');
// result: { score: 0.8, rendered: '<b>pat</b>tern' }

fuzzy-search は fuzzy をラップしており、アルゴリズム自体は同様です。

  • オブジェクト配列を扱いやすくしていますが、内部ロジックは fuzzy に依存します。
  • 複雑なスコア調整はできません。
// fuzzy-search: ラッパー使用
const searcher = new FuzzySearch(list, ['title', 'tags']);
const result = searcher.search('query');
// result: [{...}, {...}] (スコア情報は隠蔽されがち)

fuzzyset は Levenshtein Distance(編集距離)を使用します。

  • 完全一致に近いものを優先して返します。
  • 検索というより、セットへの所属判定に適しています。
// fuzzyset: 編集距離ベース
const set = new FuzzySet(['apple', 'banana']);
const result = set.get('appl');
// result: [[0.9, 'apple'], [0.4, 'banana']]

📦 データ構造の扱い:配列 vs オブジェクト

扱うデータの形状によって、ライブラリの使いやすさが変わります。

fuse.js はオブジェクト配列をネイティブにサポートします。

  • keys オプションで検索対象のフィールドを指定できます。
  • ネストされたプロパティも author.name のように指定可能です。
// fuse.js: オブジェクト配列
const books = [{ title: 'JS Guide', author: { name: 'Alice' } }];
const fuse = new Fuse(books, { keys: ['title', 'author.name'] });

fuzzy は基本的に単一の文字列を扱います。

  • オブジェクトを検索するには、自分でループを回す必要があります。
  • 追加コードが増えるため、ラッパーを使うことが多いです。
// fuzzy: 単一文字列
const matches = data.map(item => {
  return fuzzy.match(item.title, 'query');
});

fuzzy-search はオブジェクト配列に特化しています。

  • コンストラクタでキーを定義するため、毎回ループを書く必要がありません。
  • 手軽ですが、柔軟性は fuse.js に劣ります。
// fuzzy-search: オブジェクト特化
const searcher = new FuzzySearch(data, ['title', 'category']);

fuzzyset は文字列の配列(セット)を前提としています。

  • オブジェクトを扱うには、事前に文字列リストを抽出する必要があります。
  • 元データとの紐付けを自分で管理しなければなりません。
// fuzzyset: 文字列セット
const list = data.map(item => item.title);
const set = new FuzzySet(list);

⚡ パフォーマンスとインデックス:事前計算 vs Its 都度計算

データ量が増えると、検索速度がボトルネックになります。

fuse.js はインデックス機能を提供します(v7 以降)。

  • 事前計算により、検索時の計算量を減らせます。
  • 大規模データセットでも高速に動作します。
// fuse.js: インデックス利用
const fuse = new Fuse(list, { includeScore: true });
// 内部でインデックスを構築して検索高速化

fuzzy と fuzzy-search は都度計算です。

  • 検索のたびに全データに対してマッチングを行います。
  • データ量が増えると遅延が目立ち始めます。
// fuzzy: 都度計算
// 毎回全要素に対して match 関数が呼ばれる

fuzzyset も事前計算を行いますが、用途が限られます。

  • セット作成時に計算しますが、検索アルゴリズムが単純なため高速です。
  • ただし、ランキング機能は弱いです。
// fuzzyset: セット構築時計算
const set = new FuzzySet(largeList);
// 構築に時間がかかるが、get は高速

🛠️ メンテナンスとエコシステム:活性度と信頼性

ライブラリの長期維持性は、プロジェクトの安定性に影響します。

fuse.js は活発にメンテナンスされています。

  • TypeScript の型定義が充実しており、IDE サポートが手厚いです。
  • コミュニティが大きく、トラブル時の情報入手が容易です。
// fuse.js: TypeScript サポート
import { Fuse } from 'fuse.js'; // 型定義が利用可能

fuzzy と fuzzy-search は更新が停滞しています。

  • 機能追加はほぼありません。
  • 既存プロジェクトの維持としては使えますが、新規採用は慎重になるべきです。
// fuzzy: 型定義はコミュニティ依存
// npm install @types/fuzzy (別途インストールが必要な場合あり)

fuzzyset は非常に古いライブラリです。

  • 公式の npm パッケージは更新が止まっています。
  • 互換性のあるフォーク(fuzzyset.js)を使うのが現実的な選択肢です。
// fuzzyset: 非推奨リスク
// 新規プロジェクトでの使用は避けるべき

📊 比較まとめ

特徴fuse.jsfuzzyfuzzy-searchfuzzyset
アルゴリズムBitap (拡張版)単純マッチ単純マッチ (ラップ)編集距離
データ構造オブジェクト配列文字列オブジェクト配列文字列セット
重み付け✅ 可能❌ 不可❌ 不可❌ 不可
インデックス✅ 対応❌ 都度計算❌ 都度計算✅ 事前計算
メンテナンス🟢 活発🟡 停滞🟡 停滞🔴 古い
TypeScript✅ 公式対応⚠️ コミュニティ⚠️ コミュニティ❌ 非対応

💡 結論と推奨

fuse.js が現代のフロントエンド開発における最良の選択です — 機能、性能、メンテナンス性のすべてで優れています。特に、検索結果の並び順を制御したい場合や、大規模データを扱う場合は必須と言えます。

fuzzy や fuzzy-search は、既存プロジェクトの維持や、非常に単純な実装で済む場合にのみ検討してください。新規プロジェクトでは、追加の利点が少ないため避けるべきです。

fuzzyset はアルゴリズムの特性上、検索エンジンというより「入力補完の候補絞り込み」などに適しています。ただし、パッケージの古さを考慮し、フォーク版の利用や fuse.js での代替を検討してください。

最終的には、**「検索 UX の質」と「保守コスト」**のバランスで決まります。ほとんどの場合、fuse.js を選ぶことで、将来的な技術的負債を減らせます。

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

  • fuse.js:

    最新の機能、重み付け検索、アクティブなメンテナンスが必要な場合は fuse.js を選んでください。大規模なデータセットや複雑な検索要件にも対応できるため、現代のフロントエンド開発における事実上の標準です。

  • fuzzy:

    単純な文字列マッチングとハイライト表示のみで十分な場合、fuzzy が適しています。ただし機能は限定的であり、新しいプロジェクトでは代替案を検討すべきです。

  • fuzzy-search:

    オブジェクト配列の特定キーを簡単に検索したい場合、fuzzy-search が便利です。fuzzy ライブラリをラップしており、設定の手間を省きたい時に使います。

  • 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.