search-index

A persistent, network-resilient full-text search library for the browser and Node.js

Library
npm
v6.0.2
1,422stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
72/100Good
Development Activity72
Maintenance48
Community80
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
77/100Good
Architecture78
Code Quality78
Innovation68
Learning Curve85

search-index is a full-text search engine built as an importable JavaScript library rather than a hosted service, giving each application its own local, persistent inverted index instead of a shared external search cluster. It runs identically in Node.js (backed by ClassicLevel) and in the browser (backed by BrowserLevel over indexedDB), so an app can index and query documents entirely offline and ship the resulting index as a static asset.

The library exposes a small set of verbs — PUT, QUERY, SEARCH, DELETE, FACETS, BUCKETS, DICTIONARY — built on top of the fergies-inverted-index data structure, with a configurable tokenization pipeline (stemming, stopwords, n-grams, case sensitivity) that lets consumers tune how text is broken into searchable tokens. Boolean composition (AND/OR/NOT), field-scoped and ranged token queries, faceting, and TF-IDF scoring are all available through a single query object, making it a drop-in alternative to hosted search services for projects that want to keep search data local.

What You Get

  • A persistent inverted index that runs in Node.js (ClassicLevel) or the browser (BrowserLevel/indexedDB) behind the same API
  • A configurable tokenization pipeline covering stemming, stopwords, n-grams, and case sensitivity
  • Boolean query composition (AND/OR/NOT) plus faceting, bucketing, and TF-IDF scoring out of the box
  • EXPORT/IMPORT methods for backing up an index or shipping a prebuilt one as a static asset

Common Use Cases

  • Offline-capable search for documentation sites, static site generators, and PWAs that can’t depend on a network round-trip
  • Embedded search inside desktop/Electron or CLI tools where running a separate search server isn’t practical
  • Prototyping search features locally before committing to hosted search infrastructure

Under The Hood

Architecture The SearchIndex class composes a Reader and Writer around an InvertedIndex instance (from the separate fergies-inverted-index package), exposing verbs like PUT, QUERY, DELETE, and FACETS as bound arrow-function properties on the instance. Writer serializes every write through a p-queue with concurrency 1 to make read-modify-write DOCUMENT_COUNT increments safe under concurrent calls, delegating tokenization to DocumentProcessor before writing vectors to the index and then persisting raw documents via PUT_RAW. Reader recursively parses JSON query objects into AND/OR/NOT/GET calls against the index, with optional DOCUMENTS/FACETS/PAGE/SORT post-processing layered on top. Thin entrypoint modules (classiclevel.js, browserlevel.js) simply inject the appropriate Level implementation, keeping browser and Node behavior in sync through one shared core class.

Tech Stack The package is pure ESM ("type": "module") targeting Node 22+, with fergies-inverted-index providing the actual index data structure, classic-level/browser-level as pluggable abstract-level backends, lru-cache for query caching, p-queue for write serialization, and ngraminator/term-vector for tokenization. Webpack builds the browser bundle. The test/lint stack uses tape + tape-run for tests, standard for linting, and prettier for formatting, with GitHub Actions running the suite across Node 22/24/26 under xvfb for browser tests.

Code Quality The repo carries 58 test files under test/src, covering nearly every public verb (AND, OR, NOT, FACETS, BUCKETS, DELETE, EXPORT, etc.) plus dedicated regression tests named after past GitHub issues. standard enforces lint/format conventions, private class fields (#cache, #ii, #ops) are used for encapsulation in Reader/Writer, and JSDoc typedefs annotate the public API surface — though the codebase itself is plain JavaScript with no static type checking.

API Design SHOUT-CASE verb methods (PUT, QUERY, SEARCH, FACETS, …) are assigned directly as instance properties, giving a terse, consistently-named API surface without needing to worry about this binding. A single JSON query object supports nested AND/OR/NOT composition plus per-call PIPELINE overrides, avoiding a separate query-builder DSL. Getting productive requires understanding both the tokenization pipeline and abstract-level backend selection up front, which is more initial setup than a typical zero-config search library.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search