fuse.js, fuzzy-search, and fuzzysort are JavaScript libraries designed to perform approximate string matching, commonly known as fuzzy search. They allow users to find relevant results even when typos occur or when the search query does not exactly match the data. fuse.js is a full-featured search engine with weighted scoring and deep configuration. fuzzysort focuses on raw speed and simplicity with a small footprint. fuzzy-search offers a basic implementation often used for simple list filtering with minimal setup.
When building search features in web applications, exact matching is rarely enough. Users make typos, forget words, or type partial strings. fuse.js, fuzzy-search, and fuzzysort solve this by allowing approximate matching, but they differ significantly in speed, features, and API design. Let's break down how they handle real-world search scenarios.
fuse.js requires creating an instance with your data and configuration options.
// fuse.js: Initialize with options
import Fuse from 'fuse.js';
const options = {
keys: ['title', 'author'],
threshold: 0.3
};
const fuse = new Fuse(bookList, options);
fuzzy-search uses a similar constructor pattern but with fewer options.
// fuzzy-search: Initialize with list and keys
import FuzzySearch from 'fuzzy-search';
const searcher = new FuzzySearch(bookList, ['title', 'author']);
fuzzysort does not require an instance.
// fuzzysort: Direct function call
import fuzzysort from 'fuzzysort';
// No instance needed, pass data directly to search
const results = fuzzysort.search('query', bookList, { keys: ['title', 'author'] });
fuse.js offers deep configuration for relevance tuning.
// fuse.js: Search with custom threshold
const results = fuse.search('harry potter', { limit: 10 });
// Options like threshold can be set during init or search
fuzzy-search keeps execution simple with minimal arguments.
// fuzzy-search: Simple search call
const results = searcher.search('harry potter', 10);
// Returns matching items directly
fuzzysort balances speed with some configuration options.
// fuzzysort: Search with options
const results = fuzzysort.search('harry potter', bookList, {
limit: 10,
threshold: -1000
});
// Returns objects with score and match data
fuse.js returns detailed match information including scores.
// fuse.js: Rich result object
// result.item -> original data
// result.score -> relevance score (lower is better)
// result.matches -> details on which keys matched
console.log(results[0].score);
fuzzy-search returns the original items by default.
// fuzzy-search: Returns original items
// results is an array of the original objects
console.log(results[0]); // Direct access to item
fuzzysort returns objects with score and target data.
// fuzzysort: Result with score and highlights
// result.score -> numeric score (higher is better)
// result.obj -> original item
console.log(results[0].score);
fuse.js is actively maintained and widely adopted.
// fuse.js: Actively maintained
// Suitable for long-term enterprise projects
import Fuse from 'fuse.js'; // Standard import
fuzzy-search has less frequent updates and community activity.
// fuzzy-search: Simpler maintenance profile
// Check npm page for recent updates before use
import FuzzySearch from 'fuzzy-search';
fuzzysort is optimized for speed and written in TypeScript.
// fuzzysort: High performance focus
// Ideal for command palettes and large lists
import fuzzysort from 'fuzzysort';
| Feature | fuse.js | fuzzy-search | fuzzysort |
|---|---|---|---|
| Setup | Instance with options | Instance with keys | Direct function call |
| Config | High (weights, threshold) | Low (basic) | Medium (threshold, limit) |
| Results | Item + Score + Matches | Item only | Item + Score + Highlights |
| Speed | Moderate | Moderate | Very Fast |
| Maintenance | Active | Less Active | Active |
fuse.js is the safest choice for most applications โ it balances features, stability, and community support. Use it when search relevance is critical and you need to tune how matches are scored.
fuzzysort is the performance specialist โ pick it for command palettes, large datasets, or when every millisecond counts. Its TypeScript support is a bonus for modern stacks.
fuzzy-search is the lightweight option โ suitable for small tools or legacy code where adding a heavier library is not worth it. For new projects, prefer fuse.js or fuzzysort for better long-term support.
Choose fuse.js if you need advanced features like weighted search keys, nested object support, and customizable scoring thresholds. It is the industry standard for complex search requirements where accuracy and configuration matter more than raw speed. Ideal for documentation sites, large datasets, and applications needing fine-tuned relevance.
Choose fuzzy-search if you need a very simple, lightweight solution for small lists and do not require advanced weighting or scoring. It works well for legacy projects or quick prototypes where adding a heavier dependency is not justified. Avoid for large-scale applications needing high performance or complex matching rules.
Choose fuzzysort if performance is your top priority and you need fast results on large lists without complex configuration. It is perfect for command palettes, quick filters, and TypeScript projects that benefit from its built-in types. Best when you need speed over advanced weighting features.
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.