Simple full-text search in your browser.
A bit like Solr, but much smaller and not as bright.
A very simple search index can be created using the following:
var idx = lunrthisfield'title' boost: 10thisfield'body'
Adding documents to be indexed is as simple as:
var doc ="title": "Twelfth-Night""body": "If music be the food of love, play on: Give me excess of it…""author": "William Shakespeare""id": 1idxadddoc
Then searching is as simple:
This returns a list of matching documents with a score of how closely they match the search query:
"ref": 1"score": 0.87533
Lunr.js is a small, full-text search library for use in the browser. It indexes JSON documents and provides a simple search interface for retrieving documents that best match text queries.
For web applications with all their data already sitting in the client, it makes sense to be able to search that data on the client too. It saves adding extra, compacted services on the server. A local search index will be quicker, there is no network overhead, and will remain available and useable even without a network connection.
Simply include the lunr.js source file in the page that you want to use it. Lunr.js is supported in all modern browsers.