gitmyhub

lunr.js

JavaScript ★ 9.2k updated 1y ago

A bit like Solr, but much smaller and not as bright

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.

JavaScriptnpmsetup: easycomplexity 2/5

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.

Where it fits