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
- Execute the following command in Command Prompt by navigating to
my-website
directory.
npm install @easyops-cn/docusaurus-search-local
- 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.
- Execute the following command.
npm run build
- Execute the following command.
npm run serve
Your Docusarus site opens with a search bar enabled. Test it.