Skip to main content
Version: 2.0

Enable Documentation Search

In this section, let’s explore how we can enable search operation in our Docusaurus site. We will use Lunr.js search.

Setup

  1. Execute the following command in Command Prompt by navigating to my-website directory.
npm install @easyops-cn/docusaurus-search-local
  1. Paste the following code in `docusaurus.config.js` file.
plugins: [
[
'@easyops-cn/docusaurus-search-local',
{
indexDocs: true, // index your docs
indexBlog: false, // disable blog indexing (set true if you have blog)
indexPages: false, // disable pages indexing
hashed: false, // use false for better compatibility
docsRouteBasePath: '/', // adjust if your docs path is different
language: 'en', // language of your docs
highlightSearchTermsOnTargetPage: true,
},
],
],

The code snippet when inserted should look like this.

note

If you are using blogs on your site, set the indexBlog variable to True.

  1. Execute the following command.
npm run build  
  1. Execute the following command.
npm run serve   

Your Docusarus site opens with a search bar enabled. Test it.