gatsby-plugin-lunr-search
A plugin for Gatsby to generate a search index that you can use with Lunr.
Inspired by gatsby-plugin-elasticlunr-search
.
Getting started
yarn add --dev lunr gatsby-plugin-lunr-search
Usage
// gatsby-config.jsplugins: resolve: 'gatsby-plugin-lunr-search' options: // Lunr reference ref: 'id' // Fields to be indexed fields: 'title' 'description' // Nodes to be indexed resolvers: // Index all `MarkdownRemark` nodes MarkdownRemark: nodeid nodefrontmattertitle nodefrontmatterdescription
Then you can query for the search index in your pages and components. The search index is a JSON string, so you have to parse the JSON.
;;; state = results: ; { const data = thisprops; const index = Index; this; } { const results = thisstate; if resultslength > 0 return results; return <div>Could not find any results</div>; } const query = graphql` query SearchIndex { searchIndex { index } }`;