3.5.0 • Published 3 months ago

docusaurus-lunr-search v3.5.0

Weekly downloads
4,392
License
MIT
Repository
github
Last release
3 months ago

docusaurus-lunr-search

Offline Search for Docusaurus V2 or V3

Demo Website

MIT Licence

npm version

Sample

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

  1. Some time npm fails to install lunr package, in that case install lunr package manually
npm i lunr --save
  1. Add the docusaurus-lunr-search plugin to your docusaurus.config.js
module.exports = {
  // ...
    plugins: [require.resolve('docusaurus-lunr-search')],
}
  1. Then build your Docusaurus project
yarn build

or

npm run build
  1. 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

OptionTypeDefaultDescription
languagesArray['en']Language codes to use for stemming, Supports all the language listed here https://github.com/MihaiValentin/lunr-languages
indexBaseUrlBooleanfalseBase url will not indexed by default, if you want to index the base url set this option to true
excludeRoutesArray[]Exclude certain routes from the search
includeRoutesArray[]Include only specific routes for search
stopWordsArray[]Add stop words(words that are exclude from search result) to the search index
excludeTagsArray[]Exclude certain tags from the search
highlightResultBooleanfalseEnable it to highlight the searched word in the result page. Used mark.js for highlighting. You can customize the highlight color using css mark { background-color: red !important; color: green !important }
disableVersioningBooleanfalseDocs versions are displayed by default. If you want to hide it, set this plugin option to true
assetUrlstring\ | Url from which the generated search doc files to be loaded, check issue #122
maxHitsstring5Maximum number of hits shown
fieldsobject{}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, 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:

{ 
  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 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, I modified it to create this search component

And thanks cmfcmf, I used the code from his library docusaurus-search-local for multi-language support.

Changelog

Checkout the releases page for changelog.

3.5.0

3 months ago

3.4.0

7 months ago

3.3.2

11 months ago

3.3.1

12 months ago

2.4.1

1 year ago

2.4.0

1 year ago

2.4.2

1 year ago

3.3.0

1 year ago

3.2.0

1 year ago

3.1.0

1 year ago

3.0.0

1 year ago

2.3.0

2 years ago

2.3.2

2 years ago

2.3.1

2 years ago

2.2.0

2 years ago

2.1.16

2 years ago

2.1.15

3 years ago

2.1.14

4 years ago

2.1.13

4 years ago

2.1.12

4 years ago

2.1.11

4 years ago

2.1.10

4 years ago

2.1.9

4 years ago

2.1.8

4 years ago

2.1.7

4 years ago

2.1.6

4 years ago

2.1.5-rc2

4 years ago

2.1.5

4 years ago

2.1.5-rc1

4 years ago

2.1.2

4 years ago

2.1.4

4 years ago

2.1.3

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.0-zh1

4 years ago

2.0.1

4 years ago

2.0.0-rc3

4 years ago

2.0.0-rc2

4 years ago

2.0.0-rc1

4 years ago

2.0.0

4 years ago

1.0.3-rc1

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago