# docusaurus-lunr-search

> Offline search component for Docusaurus V3

Latest version **3.6.0** (published 2025-01-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install docusaurus-lunr-search
pnpm add docusaurus-lunr-search
yarn add docusaurus-lunr-search
bun add docusaurus-lunr-search
```

## Health

**Score 35/100 (D)** — status: stable.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 3.6.0 |
| Published | 2025-01-10 |
| First published | 2020-04-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 8.10.0 |
| Dependencies | 14 |
| Unpacked size | 97.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 558 |
| Author | Praveen N |
| Maintainers | lelouch77 |
| Keywords | docusaurus, lunr, offline-search, documentation |

## Links

- npm: https://www.npmjs.com/package/docusaurus-lunr-search
- Repository: https://github.com/lelouch77/docusaurus-lunr-search
- Homepage: https://github.com/lelouch77/docusaurus-lunr-search/blob/master/README.md
- Issues: https://github.com/lelouch77/docusaurus-lunr-search/issues
- npm.io page: https://npm.io/package/docusaurus-lunr-search

## Dependencies (14)

- [clsx](https://npm.io/package/clsx.md) ^2.1.1
- [lunr](https://npm.io/package/lunr.md) ^2.3.9
- [gauge](https://npm.io/package/gauge.md) ^3.0.2
- [mark.js](https://npm.io/package/mark.js.md) ^8.11.1
- [unified](https://npm.io/package/unified.md) ^9.2.2
- [hogan.js](https://npm.io/package/hogan.js.md) ^3.0.2
- [to-vfile](https://npm.io/package/to-vfile.md) ^6.1.0
- [minimatch](https://npm.io/package/minimatch.md) ^3.1.2
- [rehype-parse](https://npm.io/package/rehype-parse.md) ^7.0.1
- [unist-util-is](https://npm.io/package/unist-util-is.md) ^4.1.0
- [lunr-languages](https://npm.io/package/lunr-languages.md) ^1.4.0
- [autocomplete.js](https://npm.io/package/autocomplete.js.md) ^0.37.1
- [hast-util-select](https://npm.io/package/hast-util-select.md) ^4.0.2
- [hast-util-to-text](https://npm.io/package/hast-util-to-text.md) ^2.0.1

## Alternatives

- [@cantoo/pdf-lib](https://npm.io/package/@cantoo/pdf-lib.md) — 297.9K weekly downloads
- [datatables.net-buttons](https://npm.io/package/datatables.net-buttons.md) — 200.1K weekly downloads
- [@ckeditor/ckeditor5-export-pdf](https://npm.io/package/@ckeditor/ckeditor5-export-pdf.md) — 167.0K weekly downloads
- [scanbot-web-sdk](https://npm.io/package/scanbot-web-sdk.md) — 15.0K weekly downloads
- [@syncfusion/ej2-angular-pdfviewer](https://npm.io/package/@syncfusion/ej2-angular-pdfviewer.md) — 8.8K weekly downloads

## Recent versions

- 3.6.0 (latest) — 2025-01-10
- 3.6.1 — 2025-01-10
- 3.5.0 — 2024-09-08
- 3.4.0 — 2024-05-08
- 3.3.2 — 2024-01-06
- 3.3.1 — 2023-12-09
- 3.3.0 — 2023-11-10
- 3.2.0 — 2023-10-16
- 3.1.0 — 2023-10-15
- 3.0.0 — 2023-09-16
- 2.4.2 — 2023-09-02
- 2.4.1 — 2023-08-19
- 2.4.0 — 2023-08-16
- 2.3.2 — 2022-11-14
- 2.3.1 — 2022-11-11
- … 32 more at https://npm.io/package/docusaurus-lunr-search/versions

## README

# docusaurus-lunr-search
Offline Search for Docusaurus V2 or V3

[Demo Website](https://praveenn77.github.io/docusaurus-lunr-search-demo/)

 [![MIT Licence](https://img.shields.io/github/license/lelouch77/docusaurus-lunr-search)](#)

[![npm version](https://badge.fury.io/js/docusaurus-lunr-search.svg)](https://www.npmjs.com/package/docusaurus-lunr-search)

## Sample
<p align="center">
<img width="548" alt="image" src="https://github.com/praveenn77/docusaurus-lunr-search/assets/20218070/dbc54b61-077f-4e11-af27-8798cae8a572.gif">
</p>


## Prerequisites
- Docusaurus V2 or V3
- Node.js >= 12.X

## How to Use ?
1. Install this package
```
yarn add docusaurus-lunr-search
```
or
```
npm i docusaurus-lunr-search  --save
```
If npm install fails to install with error `unable to resolve dependency tree`, run `npm i --legacy-peer-deps`

2. Some time npm fails to install `lunr` package, in that case install `lunr` package manually
```
npm i lunr --save
```

3. Add the docusaurus-lunr-search plugin to your `docusaurus.config.js`
```
module.exports = {
  // ...
    plugins: [require.resolve('docusaurus-lunr-search')],
}
```

4. Then build your Docusaurus project
```
yarn build
```
or
```
npm run build
```

5. Serve your application
```
yarn serve
```
or
```
npm run serve 
```

Note: Docusaurus search information can only be generated from a production build. Local development is currently not supported.

## Using an option (eg. `languages`) in the plugin
```
module.exports = {
  // ...
    plugins: [[ require.resolve('docusaurus-lunr-search'), {
      languages: ['en', 'de'] // language codes
    }]],
}
```
Supports all the language listed here https://github.com/MihaiValentin/lunr-languages

## Options available

| Option              | Type      | Default  | Description                                                                                                               |
| ------------------- | --------- | -------- | ------------------------------------------------------------------------------------------------------------------------- |
| `languages`         | `Array`   | `['en']` | Language codes to use for stemming, Supports all the language listed here https://github.com/MihaiValentin/lunr-languages |
| `indexBaseUrl`      | `Boolean` | `false`  | Base url will not indexed by default, if you want to index the base url set this option to `true`                         |
| `excludeRoutes`     | `Array`   | `[]`     | Exclude certain routes from the search                                                                                    |
| `includeRoutes`     | `Array`   | `[]`     | Include only specific routes for search                                                                                   |
| `stopWords`         | `Array`   | `[]`     | Add stop words(words that are exclude from search result) to the search index                                             |
| `excludeTags`       | `Array`   | `[]`     | Exclude certain tags from the search      
| `highlightResult`   | `Boolean` | `false`  | Enable it to highlight the searched word in the result page. Used `mark.js` for highlighting. <br /> You can customize the highlight color using css <br /> ``` mark  { background-color: red !important; color: green !important }```                                                                                |
| `disableVersioning` | `Boolean` | `false`  | Docs versions are displayed by default. If you want to hide it, set this plugin option to `true`                          |
| `assetUrl`     | `string`   | `\`     | Url from which the generated search doc files to be loaded, check [issue #122](https://github.com/praveenn77/docusaurus-lunr-search/issues/122) |
| `maxHits`           | `string`  | `5`      | Maximum number of hits shown |
| `fields`            | `object`  | `{}`      | Lunr field definitions, allows "boosting" priority for different sources of keywords (e.g. title, content, keywords) |

### Options to configure Lunr fields
The `fields` config property is passed into Lunr directly as [field attributes](https://lunrjs.com/docs/lunr.Builder.html#field), and can be used to configure the relative priority of different field types (e.g. title, content, keywords). 

docusaurus-lunr-search sets the default value for fields to:

```javascript
{ 
  title: { boost: 200 },
  content: { boost: 2 },
  keywords: { boost: 100 }
}
```

## Indexing non-direct children headings of `.markdown`
By default, this library will only search for headings that are
**direct children** of the `.markdown` element. 

If you would like to render content inside the `.markdown` element on
a swizzled DocItem component, and want this library to **index the
headings inside those custom elements even if they are not direct
children of the `.markdown` element**, then add the attribute
`data-search-children` to a parent element of the headings you want to
index.

The `data-search-children` attribute will cause this library to look
for all headings inside that element, including both direct and
indirect children (E.g. 'grandchildren' nodes).

Check this [issue #115](https://github.com/praveenn77/docusaurus-lunr-search/issues/115) for more details.

## Upgrading from docusaurus V2 to V3
Update the `docusaurus-lunr-search` version to `3.3.0` or higher in `package.json` file

Remove `src/theme/SearchBar` folder if you swizzled it before, if the folder does not exist then ignore this step.

Do `yarn install` or `npm install` 

If npm install fails to install with error `unable to resolve dependency tree`, run `npm i --legacy-peer-deps`

## Credits

Thanks to [`algolia/docsearch.js`](https://github.com/algolia/docsearch), I modified it to create this search component 

And thanks [cmfcmf](https://github.com/cmfcmf), I used the code from his library [docusaurus-search-local](https://github.com/cmfcmf/docusaurus-search-local) for multi-language support.

## Changelog
Checkout the [releases](https://github.com/lelouch77/docusaurus-lunr-search/releases) page for changelog.

---
_Source: https://npm.io/package/docusaurus-lunr-search · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
