[#]: subject: "Implement client-side search on your website with this JavaScript tool"
[#]: via: "https://opensource.com/article/21/11/client-side-javascript-search-lunrjs"
[#]: author: "Ayush Sharma https://opensource.com/users/ayushsharma"
[#]: collector: "lujun9972"
[#]: translator: " "
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
Implement client-side search on your website with this JavaScript tool
======
Lunr.js is a great option for providing search functionality on a
website or application.
![magnifying glass for search on a blue background][1]
Search is a must-have for any website or application. A simple search widget can allow users to comb through your entire blog. Or allow customers to browse your inventory. Building a custom photo gallery? Add a search box. Website search functionality is available from a variety of third-party vendors. Or you can take the DIY approach and build the entire backend to answer search API calls.
[Lunr.js][2] works on the client-side through JavaScript. Instead of sending calls to a backend, Lunr looks up search terms in an index built on the client-side itself. This avoids expensive back-and-forth network calls between the browser and your server. There are plenty of tutorials online to showcase Lunr's website search functionality. But you can actually use Lunr.js to search any array of JavaScript objects.
In this how-to, I build a search index for the [top 100 books of all time][3]. After that, I show you how to pre-build the index for faster indexing. I'll also show you how to make the most of Lunr's search options. And finally, I'll show off [findmymastodon.com][4]—a real-world implementation of Lunr.
### Getting started with Lunr.js
Create a new HTML page called `lunr.html`. I use this file throughout this guide. At the top of `lunr.html`, call the main Lunr JS library.
```
``
```
**Note:** You can find the [complete code here][5]
### Loading the dataset
Next, create a variable called `my_big_json`. This variable will contain the JSON-ified string of the main dataset. Define the variable in `lunr.html` within the `