Introduction
FlexSearch is a full-text search library for JavaScript that provides memory-efficient indexing and sub-millisecond query performance. It runs in both browser and Node.js environments with zero external dependencies, making it suitable for client-side search in web applications and server-side indexing.
What FlexSearch Does
- Indexes and searches text content with configurable tokenizers and scoring
- Supports async processing and Web Worker offloading for non-blocking search
- Provides document-based indexing with field-specific search and tag filtering
- Enables persistent storage through export and import of index data
- Offers multiple built-in language presets and custom encoder support
Architecture Overview
FlexSearch uses a context-based scoring algorithm that builds an inverted index with positional context for each indexed term. The library stores index data in a compact trie structure optimized for memory efficiency. Queries are resolved by intersecting matching result sets across context layers, with configurable resolution depth controlling the trade-off between precision and speed.
Self-Hosting & Configuration
- Install via npm or include as a script tag for browser usage
- Configure charset encoding, tokenizer mode (strict, forward, reverse, full), and resolution
- Use the Document class for multi-field indexing with per-field options
- Enable Web Worker mode by setting worker count in the constructor
- Export index state to JSON for persistence and restore on application restart
Key Features
- Sub-millisecond search on datasets with hundreds of thousands of documents
- Context-based relevance scoring without external ranking dependencies
- Built-in support for 12 languages with phonetic matching and accent handling
- Zero dependencies and under 6 KB gzipped for the compact build
- Incremental indexing with efficient add, update, and remove operations
Comparison with Similar Tools
- Lunr.js — Simpler API but slower on large datasets and lacks Web Worker support
- Fuse.js — Fuzzy search focused; not a full inverted index so less precise on exact matches
- MiniSearch — Similar feature set but FlexSearch offers more tokenizer options and context scoring
- Elasticsearch — Server-based distributed engine; overkill for client-side or embedded use cases
FAQ
Q: Can FlexSearch run entirely in the browser? A: Yes, it requires no backend and runs in any modern browser with optional Web Worker support.
Q: How large a dataset can FlexSearch handle? A: It efficiently indexes hundreds of thousands of documents in-memory; exact limits depend on available RAM.
Q: Does FlexSearch support fuzzy matching? A: It supports phonetic encoding and configurable tokenizer modes but is not primarily a fuzzy search library.
Q: Can I persist the index across page reloads? A: Yes, use the export/import methods to serialize the index to localStorage, IndexedDB, or a file.