explaingit

olivernn/lunr.js

9,202JavaScriptAudience · developerComplexity · 2/5Setup · easy

TLDR

Lunr.js is a JavaScript library that adds fast full-text search to any website without a server, build the index in the browser and users get instant, offline-capable search across 14 languages.

Mindmap

mindmap
  root((lunr.js))
    What it does
      Full text search
      No server needed
      Offline capable
    Features
      14 languages
      Fuzzy matching
      Field boosting
      Wildcard search
    Install
      npm package
      Script tag
    Use cases
      Static sites
      Docs search
      Web apps
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Add instant search to a static site or documentation site so users find content without any server round-trip.

USE CASE 2

Build an offline-capable search feature in a web app that keeps working when the user has no internet connection.

USE CASE 3

Search blog posts or knowledge base articles with fuzzy matching to catch typos and spelling variations.

Tech stack

JavaScriptnpm

Getting it running

Difficulty · easy Time to first run · 5min

No server needed, installs via npm or a script tag and runs entirely in the browser.

In plain English

Lunr.js is a JavaScript library that adds search functionality directly to a website or web application, without needing to send queries to a server. You build a search index from your existing data in the browser, and users can then search that data instantly with no network requests required. The setup is simple: you define which fields in your data should be searchable (for example, a title and a body), add documents to the index, and call a search function with a query string. It returns a ranked list of matching documents along with scores indicating how well each one matches. The main reason to use this approach is that it suits web applications where all the data is already loaded on the page. Searches run locally, so there is no server round-trip, results appear quickly, and search continues to work even when the user is offline. The library supports full-text search across 14 languages. You can boost certain terms or entire documents to make them rank higher in results, limit a search to specific fields, and use fuzzy matching to catch misspellings or slight variations via wildcards or edit distance. Lunr.js is small enough to include directly in a web page via a script tag, or you can install it through npm with a single command. It works in all modern browsers. API documentation is available on the project website, along with a working example showing it in action.

Copy-paste prompts

Prompt 1
I have a list of blog posts with title and body fields. Write JavaScript using lunr.js to build a search index and return the top 5 matching posts for a query.
Prompt 2
How do I add fuzzy matching to lunr.js so it catches typos like 'JavaScrpt' when someone searches for 'JavaScript'?
Prompt 3
I want to boost search results from the title field over the body field in lunr.js, show me how to configure field boosting.
Prompt 4
How do I add lunr.js search to a static site generated with 11ty or Jekyll, pre-building the index from a JSON file?
Open on GitHub → Explain another repo

← olivernn on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.