FlexSearch: A High-Performance Full-Text Search Library for Browser and Node.js

FlexSearch: A High-Performance Full-Text Search Library for Browser and Node.js

Summary

FlexSearch is a next-generation full-text search library designed for both browser and Node.js environments. It offers unparalleled speed, performing queries up to 1,000,000 times faster than other libraries, while providing powerful search capabilities. Developers can leverage its features for multi-field search, phonetic transformations, partial matching, and persistent indexing across various databases.

Repository Info

Updated on April 9, 2026
View on GitHub

Introduction

FlexSearch is a cutting-edge full-text search library engineered for exceptional performance in both browser and Node.js applications. It stands out for its incredible speed, capable of executing queries significantly faster than many alternatives, and its rich set of advanced search functionalities. Whether you need to implement instant search, autocomplete, or complex document indexing, FlexSearch provides a robust and efficient solution.

Key features include multi-field document search, phonetic and fuzzy matching, partial matching, tag search, and result highlighting. It also supports scalable workloads through web workers and offers persistent indexing across a variety of databases like IndexedDB, Redis, SQLite, Postgres, MongoDB, and Clickhouse. FlexSearch has been recognized for its innovation, even nominated for "Best Technology of the Year" by GitNation.

Installation

Getting started with FlexSearch is straightforward. You can install it via npm for Node.js projects or include it directly in your browser-based applications using a script tag or module import.

For Node.js:

npm install flexsearch

For browser environments, you can use a CDN or download the distribution files:

<!-- Via CDN for a bundled, minified module -->
<script type="module" src="https://cdn.jsdelivr.net/gh/nextapps-de/flexsearch@0.8.2/dist/flexsearch.bundle.module.min.js"></script>

<!-- Or for a legacy script -->
<script src="https://cdn.jsdelivr.net/gh/nextapps-de/flexsearch@0.8.2/dist/flexsearch.bundle.min.js"></script>

Examples

FlexSearch offers different index types to suit various needs: Index for flat id-content pairs, Worker for background processing, and Document for multi-field JSON documents. Here's a basic example of how to create an index, add items, and perform a search.

Basic Index Usage:

import { Index } from "flexsearch"; // For ESM
// const { Index } = require("flexsearch"); // For CommonJS

const index = new Index();

// Add items to the index
index.add(0, "John Doe");
index.add(1, "Jane Smith");
index.add(2, "Peter Jones");

// Search for items
const results = index.search("John");
console.log(results); // Expected: [0]

// Search with a limit
const limitedResults = index.search("Doe", 1); 
console.log(limitedResults); // Expected: [0]

// Update an item
index.update(0, "Jonathan Doe");
const updatedResults = index.search("Jonathan");
console.log(updatedResults); // Expected: [0]

// Remove an item
index.remove(1);
const removedResults = index.search("Jane");
console.log(removedResults); // Expected: []

For more advanced scenarios, such as document search, persistent indexes, or using web workers, refer to the comprehensive documentation and examples provided in the official repository.

Why Use FlexSearch?

FlexSearch stands out due to several compelling advantages:

  • Blazing Fast Performance: Benchmarks show FlexSearch performing queries up to 1,000,000 times faster than competing libraries, making it ideal for performance-critical applications.
  • Advanced Search Capabilities: It supports a wide array of features including multi-field search, phonetic transformations, partial matching, tag search, and result highlighting, offering a highly flexible search experience.
  • Scalability with Workers: For larger workloads, FlexSearch can leverage web workers to perform updates and queries in parallel, ensuring smooth operation without blocking the main thread.
  • Persistent Indexes: The library supports persistent indexes with various database backends like IndexedDB, Redis, SQLite, Postgres, MongoDB, and Clickhouse, enabling zero-latency boot-up and efficient handling of large datasets.
  • Multi-Language Support: It provides robust charset collections and language-specific presets for accurate indexing and searching across different languages, including CJK, Hindi, Arabic, and Cyrillic.
  • Small Footprint: Despite its powerful features, FlexSearch maintains a relatively small memory footprint, especially with optimized configurations.

Links