fuse.js、fuzzy、fuzzy-search、fuzzyset はすべて JavaScript 環境で近似文字列検索(ファジー検索)を実現するライブラリです。ユーザーの入力ミスに強い検索ボックス、コマンドパレット、データフィルタリングなど、検索 UX を向上させるために使われます。それぞれアルゴリズムの仕組み、設定の柔軟性、メンテナンス状況に違いがあります。
フロントエンドアプリケーションにおいて、ユーザーの入力ミスに強い検索機能は必須です。fuse.js、fuzzy、fuzzy-search、fuzzyset はこの課題を解決する代表的なライブラリですが、内部構造と適性が異なります。実務での選定に役立つよう、技術的な違いを比較します。
検索の精度は、ユーザー体験に直結します。各ライブラリは異なるアルゴリズムを採用しています。
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']]
扱うデータの形状によって、ライブラリの使いやすさが変わります。
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);
データ量が増えると、検索速度がボトルネックになります。
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 は活発にメンテナンスされています。
// fuse.js: TypeScript サポート
import { Fuse } from 'fuse.js'; // 型定義が利用可能
fuzzy と fuzzy-search は更新が停滞しています。
// fuzzy: 型定義はコミュニティ依存
// npm install @types/fuzzy (別途インストールが必要な場合あり)
fuzzyset は非常に古いライブラリです。
fuzzyset.js)を使うのが現実的な選択肢です。// fuzzyset: 非推奨リスク
// 新規プロジェクトでの使用は避けるべき
| 特徴 | fuse.js | fuzzy | fuzzy-search | fuzzyset |
|---|---|---|---|---|
| アルゴリズム | Bitap (拡張版) | 単純マッチ | 単純マッチ (ラップ) | 編集距離 |
| データ構造 | オブジェクト配列 | 文字列 | オブジェクト配列 | 文字列セット |
| 重み付け | ✅ 可能 | ❌ 不可 | ❌ 不可 | ❌ 不可 |
| インデックス | ✅ 対応 | ❌ 都度計算 | ❌ 都度計算 | ✅ 事前計算 |
| メンテナンス | 🟢 活発 | 🟡 停滞 | 🟡 停滞 | 🔴 古い |
| TypeScript | ✅ 公式対応 | ⚠️ コミュニティ | ⚠️ コミュニティ | ❌ 非対応 |
fuse.js が現代のフロントエンド開発における最良の選択です — 機能、性能、メンテナンス性のすべてで優れています。特に、検索結果の並び順を制御したい場合や、大規模データを扱う場合は必須と言えます。
fuzzy や fuzzy-search は、既存プロジェクトの維持や、非常に単純な実装で済む場合にのみ検討してください。新規プロジェクトでは、追加の利点が少ないため避けるべきです。
fuzzyset はアルゴリズムの特性上、検索エンジンというより「入力補完の候補絞り込み」などに適しています。ただし、パッケージの古さを考慮し、フォーク版の利用や fuse.js での代替を検討してください。
最終的には、**「検索 UX の質」と「保守コスト」**のバランスで決まります。ほとんどの場合、fuse.js を選ぶことで、将来的な技術的負債を減らせます。
最新の機能、重み付け検索、アクティブなメンテナンスが必要な場合は fuse.js を選んでください。大規模なデータセットや複雑な検索要件にも対応できるため、現代のフロントエンド開発における事実上の標準です。
単純な文字列マッチングとハイライト表示のみで十分な場合、fuzzy が適しています。ただし機能は限定的であり、新しいプロジェクトでは代替案を検討すべきです。
オブジェクト配列の特定キーを簡単に検索したい場合、fuzzy-search が便利です。fuzzy ライブラリをラップしており、設定の手間を省きたい時に使います。
セットの所属検査が主目的で、検索ランキングが次要的な場合は fuzzyset を検討できます。ただしメンテナンスが停滞しているため、長期プロジェクトでは注意が必要です。
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.
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.
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.
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>
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', ... }, ... }]
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' } }]
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 }
]
})
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
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
"patterns javascript" and "javascript patterns" return identical resultstokenMatch: 'all' returns only records matching every word (filtering); the default 'any' matches any wordtokenize for tokens with internal punctuation (node.js, c++), or use Intl.Segmenter for CJK / Thai word segmentation. Unicode-aware by defaultAvailable in the full build. See the Token Search docs for details and performance benchmarks.
Combine conditions with $and and $or for complex queries. Available in the full build.
fuse.search({
$and: [
{ title: 'javascript' },
{ author: 'crockford' }
]
})
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]]
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.
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')
Fuse.js ships in two variants:
| Build | Includes | Min + gzip |
|---|---|---|
| Full | Fuzzy + Extended + Logical + Token search | ~8.6 kB |
| Basic | Fuzzy search only | ~6.8 kB |
Use the basic build if you only need fuzzy search and want the smallest bundle size.
For the full API reference, configuration options, scoring theory, and interactive demos, visit fusejs.io.
See DEVELOPERS.md for setup, scripts, and project structure.
See CONTRIBUTING.md for guidelines on issues and pull requests.