{"_id":"@andrew-codes/gatsby-plugin-elasticlunr-search","_rev":"4-456410311e99e03a6d732fdf846479f1","name":"@andrew-codes/gatsby-plugin-elasticlunr-search","description":"Search for gatsby; implemented via elastic lunr.","dist-tags":{"latest":"1.0.4"},"versions":{"1.0.2":{"name":"@andrew-codes/gatsby-plugin-elasticlunr-search","version":"1.0.2","description":"Search for gatsby; implemented via elastic lunr.","main":"index.js","scripts":{"start":"nps","test":"nps test"},"repository":{"type":"git","url":"git+https://github.com/andrew-codes/gatsby-plugin-search.git"},"keywords":["gatsby","gatsby-plugin","lunr","search","elastic lunr"],"author":{"name":"Andrew Smith","email":"andrew@andrew.codes"},"license":"MIT","bugs":{"url":"https://github.com/andrew-codes/gatsby-plugin-search/issues"},"homepage":"https://github.com/andrew-codes/gatsby-plugin-search#readme","devDependencies":{"@babel/cli":"^7.0.0-beta.32","@babel/core":"^7.0.0-beta.32","@babel/plugin-proposal-object-rest-spread":"^7.0.0-beta.32","@babel/preset-env":"^7.0.0-beta.32","nps":"^5.7.1","nps-utils":"^1.5.0"},"dependencies":{"elasticlunr":"^0.9.5","graphql":"^0.11.7"},"gitHead":"84ebea7b207229d77dc09719711cefc00dde99ab","_id":"@andrew-codes/gatsby-plugin-elasticlunr-search@1.0.2","_npmVersion":"5.5.1","_nodeVersion":"6.11.3","_npmUser":{"name":"andrew-codes","email":"andrew@andrew.codes"},"dist":{"integrity":"sha512-i3Ma7feFR2rK/sLkExj9qdfYXulxyinq7gnAh/ypl8xwA3hyrQJVdVAk/2K6/KyzvYTABPGlML582fabJ86HRg==","shasum":"4c3034a18db81f5e1348c8286cf960578bbcf11b","tarball":"https://registry.npmjs.org/@andrew-codes/gatsby-plugin-elasticlunr-search/-/gatsby-plugin-elasticlunr-search-1.0.2.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHiNAXQZjaiKK9cjgMAtFeI1azDci1mJw2VH2PZjl36xAiAAjjSZ8lSfdFVOg2BzFh4oDgYv3ljUJKpBdtfUjRUshw=="}]},"maintainers":[{"name":"andrew-codes","email":"andrew@andrew.codes"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/gatsby-plugin-elasticlunr-search-1.0.2.tgz_1511146921055_0.7883596010506153"},"directories":{}},"1.0.3":{"name":"@andrew-codes/gatsby-plugin-elasticlunr-search","version":"1.0.3","description":"Search for gatsby; implemented via elastic lunr.","main":"index.js","scripts":{"start":"nps","test":"nps test"},"repository":{"type":"git","url":"git+https://github.com/andrew-codes/gatsby-plugin-search.git"},"keywords":["gatsby","gatsby-plugin","lunr","search","elastic lunr"],"author":{"name":"Andrew Smith","email":"andrew@andrew.codes"},"license":"MIT","bugs":{"url":"https://github.com/andrew-codes/gatsby-plugin-search/issues"},"homepage":"https://github.com/andrew-codes/gatsby-plugin-search#readme","devDependencies":{"@babel/cli":"^7.0.0-beta.32","@babel/core":"^7.0.0-beta.32","@babel/plugin-proposal-object-rest-spread":"^7.0.0-beta.32","@babel/preset-env":"^7.0.0-beta.32","nps":"^5.7.1","nps-utils":"^1.5.0"},"dependencies":{"elasticlunr":"^0.9.5","graphql":"^0.11.7"},"gitHead":"46d2939921632ef767c51412d824ceddf449585d","_id":"@andrew-codes/gatsby-plugin-elasticlunr-search@1.0.3","_npmVersion":"5.4.2","_nodeVersion":"8.7.0","_npmUser":{"name":"andrew-codes","email":"andrew@andrew.codes"},"dist":{"integrity":"sha512-vi61ftp6v1rIw8YvkN9m6sjOSVZ7y2xc0RhN/Z2rwCMz77h+7vtI48NOlZdJ1Fml3rPSgG9O7oQvFa0gVWQ2XQ==","shasum":"2d993ced13808716e7c651fefa5ff132b54162e5","tarball":"https://registry.npmjs.org/@andrew-codes/gatsby-plugin-elasticlunr-search/-/gatsby-plugin-elasticlunr-search-1.0.3.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDJsm+1bJA8SbsNH8846q/LLFlXUZUmnqcgk95kyvNdlwIgSDTnJ9lDvRiQPn/OXrVPTBnSlMs+Ku0+obYOB3X+UQY="}]},"maintainers":[{"name":"andrew-codes","email":"andrew@andrew.codes"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/gatsby-plugin-elasticlunr-search-1.0.3.tgz_1511275026081_0.8778581854421645"},"directories":{}},"1.0.4":{"name":"@andrew-codes/gatsby-plugin-elasticlunr-search","version":"1.0.4","description":"Search for gatsby; implemented via elastic lunr.","main":"index.js","scripts":{"start":"nps","test":"nps test"},"repository":{"type":"git","url":"git+https://github.com/andrew-codes/gatsby-plugin-search.git"},"keywords":["gatsby","gatsby-plugin","lunr","search","elastic lunr"],"author":{"name":"Andrew Smith","email":"andrew@andrew.codes"},"license":"MIT","bugs":{"url":"https://github.com/andrew-codes/gatsby-plugin-search/issues"},"homepage":"https://github.com/andrew-codes/gatsby-plugin-search#readme","devDependencies":{"@babel/cli":"^7.0.0-beta.32","@babel/core":"^7.0.0-beta.32","@babel/plugin-proposal-object-rest-spread":"^7.0.0-beta.32","@babel/preset-env":"^7.0.0-beta.32","eslint":"^4.12.1","nps":"^5.7.1","nps-utils":"^1.5.0"},"dependencies":{"elasticlunr":"^0.9.5","graphql":"^0.11.7"},"gitHead":"dd6b5f813497a789c7f65fe3c1e94767b4756ffa","_id":"@andrew-codes/gatsby-plugin-elasticlunr-search@1.0.4","_npmVersion":"5.7.1","_nodeVersion":"8.5.0","_npmUser":{"name":"andrew-codes","email":"andrew@andrew.codes"},"dist":{"integrity":"sha512-P6RR3oAl1BVNhEZBXst/KEXLi2T2x2D6J6UBwmsgZNf0lLtHL/7N68KeLN+J2VKcAmvDpJ83o2KEj3ft/jND8g==","shasum":"2b2ace31903177961198b1e218f882667a31f228","tarball":"https://registry.npmjs.org/@andrew-codes/gatsby-plugin-elasticlunr-search/-/gatsby-plugin-elasticlunr-search-1.0.4.tgz","fileCount":15,"unpackedSize":40947,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDB0JKr/GaXBxA3yXdtVWnFCnn7f0jRghxV2PD80mThAQIgb3sTQRYHTFpRX3wFsV1eXh6H+OLDRcTSp0/vjJvZxWU="}]},"maintainers":[{"name":"andrew-codes","email":"andrew@andrew.codes"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/gatsby-plugin-elasticlunr-search_1.0.4_1522118828753_0.17657429784534484"},"_hasShrinkwrap":false}},"readme":"[![Maintainability](https://api.codeclimate.com/v1/badges/124348de2ee6850d682f/maintainability)](https://codeclimate.com/github/andrew-codes/gatsby-plugin-elasticlunr-search/maintainability)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/7230ae7191f44a9489834553760310c2)](https://www.codacy.com/app/andrew-codes/gatsby-plugin-elasticlunr-search?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=andrew-codes/gatsby-plugin-elasticlunr-search&amp;utm_campaign=Badge_Grade)\n\n# Search Plugin for Gatsby\nThis plugin enables search integration via elastic lunr. Content is indexed and then made available via graphql to rehydrate into an `elasticlunr` index. From there, queries can be made against this index to retrieve pages by their ID.\n\n# Getting Started\n\nInstall the plugin via `npm install -D @andrew-codes/gatsby-plugin-elasticlunr-search`. See the [demo site repo](https://github.com/andrew-codes/gatsby-plugin-elasticlunr-search-demo) for more specific implementation details.\n\nNext, update your `gatsby-config.js` file to utilize the plugin.\n\n## Setup in `gatsby-config`\n```javascript\nmodule.exports = {\n    plugins: [\n        {\n            resolve: `@andrew-codes/gatsby-plugin-elasticlunr-search`,\n            options: {\n                // Fields to index\n                fields: [\n                    'title',\n                    'keywords',\n                ],\n                // How to resolve each field's value for a supported node type\n                resolvers: {\n                    // For any node of type MarkdownRemark, list how to resolve the fields' values\n                    MarkdownRemark: {\n                        title: node => node.frontmatter.title,\n                        keywords: node => node.frontmatter.keywords,\n                    },\n                },\n            },\n        },\n    ],\n};\n```\n\n## Consuming in Your Site\nThe serialized search index will be available via graphql. Once queried, a component can create a new elastic lunr index with the value retrieved from the graphql query. Search queries can be made against the hydrated search index. The results is an array of document IDs. The index can return the full document given a document ID\n\n```javascript\nimport React, {Component} from 'react';\nimport {Index} from 'elasticlunr';\n\n// Graphql query used to retrieve the serialized search index.\nexport const query = graphql`query\nSearchIndexExampleQuery {\n    siteSearchIndex {\n      index\n    }\n}`;\n\n// Search component\nexport default class Search extends Component {\n    constructor(props) {\n        super(props);\n        this.state = {\n            query: ``,\n            results: [],\n        };\n    }\n\n    render() {\n        return (\n            <div>\n                <input type=\"text\" value={this.state.query} onChange={this.search}/>\n                <ul>\n                    {this.state.results.map(page => (\n                        <li>\n                            {page.title}: {page.keywords.join(`,`)}\n                        </li>\n                    ))}\n                </ul>\n            </div>\n        );\n    }\n\n    getOrCreateIndex = () => this.index\n        ? this.index\n        // Create an elastic lunr index and hydrate with graphql query results\n        : Index.load(this.props.data.siteSearchIndex.index);\n\n    search = (evt) => {\n        const query = evt.target.value;\n        this.index = this.getOrCreateIndex();\n        this.setState({\n            query,\n            // Query the index with search string to get an [] of IDs\n            results: this.index.search(query)\n                // Map over each ID and return the full document\n                .map(({\n                ref,\n                }) => this.index.documentStore.getDoc(ref)),\n        });\n    }\n}\n```\n","maintainers":[{"name":"andrew-codes","email":"andrew@andrew.codes"}],"time":{"modified":"2022-04-04T14:00:59.609Z","created":"2017-11-20T03:02:01.986Z","1.0.2":"2017-11-20T03:02:01.986Z","1.0.3":"2017-11-21T14:37:06.986Z","1.0.4":"2018-03-27T02:47:08.827Z"},"homepage":"https://github.com/andrew-codes/gatsby-plugin-search#readme","keywords":["gatsby","gatsby-plugin","lunr","search","elastic lunr"],"repository":{"type":"git","url":"git+https://github.com/andrew-codes/gatsby-plugin-search.git"},"author":{"name":"Andrew Smith","email":"andrew@andrew.codes"},"bugs":{"url":"https://github.com/andrew-codes/gatsby-plugin-search/issues"},"license":"MIT","readmeFilename":"README.md"}