Top Related Projects
Tiny and powerful JavaScript full-text search engine for browser and Node
JS Search is an efficient, client-side search library for JavaScript and JSON objects
Next-generation full-text search library for Browser and Node.js
A bit like Solr, but much smaller and not as bright
A persistent, network resilient, full text search library for the browser and Node.js
Quick Overview
Fuse is a lightweight, fast, and flexible fuzzy-search library for JavaScript. It provides a powerful search engine that can be used to search through a large dataset and return the most relevant results. Fuse is designed to be easy to use and integrate into any web application.
Pros
- Lightweight and Fast: Fuse is a lightweight library that is designed to be fast and efficient, making it suitable for use in performance-critical applications.
- Flexible and Customizable: Fuse provides a wide range of configuration options, allowing developers to customize the search behavior to fit their specific needs.
- Supports Multiple Data Formats: Fuse can search through a variety of data formats, including JSON, CSV, and XML.
- Actively Maintained: The Fuse project is actively maintained, with regular updates and bug fixes.
Cons
- Limited to JavaScript: Fuse is a JavaScript library, which means it can only be used in web applications or Node.js environments.
- Requires Client-Side Processing: Fuse performs all of its search operations on the client-side, which can be a limitation for large datasets or low-powered devices.
- Limited to Fuzzy Search: Fuse is primarily designed for fuzzy search, which may not be suitable for all types of search use cases.
- Lack of Advanced Features: Compared to some other search libraries, Fuse may lack more advanced features such as relevance scoring, faceted search, and real-time updates.
Code Examples
Here are a few examples of how to use Fuse in your JavaScript code:
// Basic usage
const Fuse = require('fuse.js');
const options = {
includeScore: true,
keys: ['name', 'description']
};
const fuse = new Fuse(data, options);
const result = fuse.search('search query');
console.log(result);
This code creates a new Fuse instance with the provided options, and then uses the search() method to perform a search on the data array.
// Customizing the search behavior
const options = {
threshold: 0.3,
distance: 100,
location: 0,
minMatchCharLength: 1,
shouldSort: true,
findAllMatches: false,
keys: ['name', 'description']
};
const fuse = new Fuse(data, options);
const result = fuse.search('search query');
console.log(result);
This code demonstrates how to customize the search behavior of Fuse by adjusting various configuration options.
// Searching with a custom scoring function
const options = {
keys: ['name', 'description'],
scoreFn: (results) => {
return results.map(({ item, score }) => {
return { item, score: score * 2 };
});
}
};
const fuse = new Fuse(data, options);
const result = fuse.search('search query');
console.log(result);
This code shows how to use a custom scoring function to modify the search results.
Getting Started
To get started with Fuse, you can install it using npm or yarn:
npm install fuse.js
or
yarn add fuse.js
Once you have the library installed, you can import it and start using it in your JavaScript code. Here's a basic example:
import Fuse from 'fuse.js';
const data = [
{ name: 'Apple', description: 'A fruit' },
{ name: 'Banana', description: 'A yellow fruit' },
{ name: 'Cherry', description: 'A small, red fruit' }
];
const options = {
includeScore: true,
keys: ['name', 'description']
};
const fuse = new Fuse(data, options);
const result = fuse.search('fruit');
console.log(result);
This code creates a new Fuse instance with the provided data and options, and then uses the search() method to perform a search for the term "fruit". The resulting search results are logged to the console.
For more
Competitor Comparisons
Tiny and powerful JavaScript full-text search engine for browser and Node
Pros of MiniSearch
- Designed for fast in-memory full-text search with a focus on performance
- Supports advanced features like fuzzy search and field-specific boosts
- Smaller bundle size, making it more lightweight for browser usage
Cons of MiniSearch
- Less flexible scoring system compared to Fuse's customizable options
- May require more manual configuration for complex search scenarios
- Limited built-in support for approximate string matching algorithms
Code Comparison
MiniSearch:
const miniSearch = new MiniSearch({
fields: ['title', 'text'],
storeFields: ['title', 'category']
})
miniSearch.addAll(documents)
const results = miniSearch.search('query')
Fuse:
const fuse = new Fuse(list, {
keys: ['title', 'author.firstName']
})
const results = fuse.search('query')
Both libraries offer simple APIs for initializing and performing searches. MiniSearch requires explicit field definitions and document addition, while Fuse can work with existing arrays of objects more seamlessly. MiniSearch's approach may offer more control over indexing, while Fuse's setup is often more straightforward for simple use cases.
JS Search is an efficient, client-side search library for JavaScript and JSON objects
Pros of js-search
- Faster search performance, especially for large datasets
- More flexible indexing options, allowing for custom tokenization and stemming
- Smaller bundle size, which can be beneficial for web applications
Cons of js-search
- Less fuzzy matching capabilities compared to Fuse
- Fewer built-in options for result highlighting and formatting
- Less active development and community support
Code Comparison
Fuse:
const fuse = new Fuse(list, {
keys: ['title', 'author.firstName']
});
const result = fuse.search('john');
js-search:
const search = new JsSearch.Search('id');
search.addIndex('title');
search.addIndex(['author', 'firstName']);
search.addDocuments(list);
const result = search.search('john');
Both libraries offer simple APIs for setting up and performing searches. Fuse provides a more concise setup with its options object, while js-search offers more granular control over indexing. The search execution is similar in both cases, but js-search typically performs faster for larger datasets.
js-search is better suited for applications requiring high-performance searches on large amounts of data, while Fuse excels in scenarios where fuzzy matching and result highlighting are important. The choice between the two depends on specific project requirements and performance needs.
Next-generation full-text search library for Browser and Node.js
Pros of FlexSearch
- Significantly faster performance, especially for large datasets
- More memory-efficient, with lower overall resource usage
- Supports multiple languages and provides more advanced search options
Cons of FlexSearch
- Steeper learning curve due to more complex API and configuration options
- Less out-of-the-box fuzzy matching capabilities compared to Fuse
- Requires more setup and fine-tuning for optimal results
Code Comparison
FlexSearch:
const index = new FlexSearch({
encode: "icase",
tokenize: "forward",
threshold: 0
});
index.add(id, text);
const results = index.search("query");
Fuse:
const fuse = new Fuse(list, {
keys: ['title', 'author'],
threshold: 0.3
});
const results = fuse.search("query");
Both libraries offer flexible search capabilities, but FlexSearch provides more granular control over indexing and searching at the cost of simplicity. Fuse is easier to set up and use out of the box, especially for simple search scenarios, while FlexSearch excels in performance-critical applications with large datasets or complex search requirements.
A bit like Solr, but much smaller and not as bright
Pros of lunr.js
- Built-in indexing and search capabilities, allowing for faster searches on pre-indexed content
- Supports advanced search features like boosting, wildcards, and field-specific searches
- Smaller file size, making it more lightweight for client-side use
Cons of lunr.js
- Less flexible fuzzy matching compared to Fuse
- Requires pre-indexing of data, which may not be suitable for dynamic content
- Limited language support for stemming (mainly English)
Code Comparison
Fuse example:
const fuse = new Fuse(list, {
keys: ['title', 'author.firstName']
});
const result = fuse.search('john');
lunr.js example:
const idx = lunr(function () {
this.field('title');
this.field('body');
this.add(documents);
});
const results = idx.search('query');
Both libraries offer simple APIs for searching, but lunr.js requires an initial indexing step. Fuse allows for more straightforward setup and searching without pre-indexing, while lunr.js provides more advanced search capabilities at the cost of initial setup complexity.
A persistent, network resilient, full text search library for the browser and Node.js
Pros of search-index
- Designed for full-text search with advanced features like faceting and TF-IDF scoring
- Supports server-side indexing and searching, suitable for larger datasets
- Offers persistence options for storing indexes
Cons of search-index
- More complex setup and configuration compared to Fuse
- Requires Node.js environment, limiting client-side usage
- Steeper learning curve for basic search functionality
Code Comparison
search-index:
const si = require('search-index')
const { index, search } = await si({ name: 'my-index' })
await index([{ id: '1', text: 'Hello World' }])
const results = await search('World')
Fuse:
const Fuse = require('fuse.js')
const list = [{ title: 'Hello World' }]
const fuse = new Fuse(list, { keys: ['title'] })
const results = fuse.search('World')
Summary
search-index is a more powerful and feature-rich search solution, ideal for server-side applications with large datasets and complex search requirements. It offers advanced functionality but comes with a steeper learning curve and more complex setup.
Fuse, on the other hand, is lightweight and easy to use, making it suitable for client-side searching and simpler use cases. It lacks some advanced features but excels in quick implementation and flexibility across different environments.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Fuse.js
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.
𧪠Beta: 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
Available in the full build. See TOKEN_SEARCH.md 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:
| Build | Includes | Min + gzip |
|---|---|---|
| Full | Fuzzy + Extended + Logical + Token search | ~8 kB |
| Basic | Fuzzy search only | ~6.5 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.
Supporting Fuse.js
- Become a backer or sponsor on GitHub
- Become a backer or sponsor on Patreon
- One-time donation via PayPal
Develop
See DEVELOPERS.md for setup, scripts, and project structure.
Contribute
See CONTRIBUTING.md for guidelines on issues and pull requests.
Top Related Projects
Tiny and powerful JavaScript full-text search engine for browser and Node
JS Search is an efficient, client-side search library for JavaScript and JSON objects
Next-generation full-text search library for Browser and Node.js
A bit like Solr, but much smaller and not as bright
A persistent, network resilient, full text search library for the browser and Node.js
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot