Convert Figma logo to code with AI

krisk logoFuse

Lightweight fuzzy-search, in JavaScript

18,051
766
18,051
9

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

8,902

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.

8,902

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 Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Fuse.js

Node.js CI Version Downloads code style: prettier Contributors License

Supporting Fuse.js

Through contributions, donations, and sponsorship, you allow Fuse.js to thrive. Also, you will be recognized as a beacon of support to open-source developers.


Silver Sponsors


Introduction

Fuse.js is a lightweight fuzzy-search, in JavaScript, with zero dependencies.

Browser Compatibility

Fuse.js supports all browsers that are ES5-compliant (IE8 and below are not supported).

Documentation

To check out a live demo and docs, visit fusejs.io.

Develop

Here's a separate document for developers.

Contribute

We've set up a separate document for our contribution guidelines.

NPM DownloadsLast 30 Days