{"_id":"@doingitright/gatsby-plugin-flexsearch","_rev":"1-b163f07b9fd4b2912209ef319e39a2d0","name":"@doingitright/gatsby-plugin-flexsearch","dist-tags":{"latest":"2.0.0"},"versions":{"2.0.0":{"name":"@doingitright/gatsby-plugin-flexsearch","version":"2.0.0","description":"Search for Gatsby.js using FlexSearch.js","main":"index.js","homepage":"https://github.com/brandonfancher/gatsby-plugin-flexsearch#readme","keywords":["gatsby","gatsby-plugin","search","flexsearch"],"author":{"name":"Tiago Santos"},"contributors":[{"name":"Tiago Santos"},{"name":"Brandon Fancher","email":"brandonfancher@gmail.com","url":"http://brandonfancher.com"}],"license":"MIT","dependencies":{"flexsearch":"^0.6.32","fs":"^0.0.1-security"},"devDependencies":{"babel-eslint":"^9.0.0","eslint":"^5.14.1","eslint-config-airbnb":"^17.1.0","eslint-config-prettier":"^4.1.0","eslint-config-wesbos":"0.0.19","eslint-plugin-html":"^5.0.3","eslint-plugin-import":"^2.16.0","eslint-plugin-jsx-a11y":"^6.2.1","eslint-plugin-prettier":"^3.0.1","eslint-plugin-react":"^7.12.4","eslint-plugin-react-hooks":"^1.3.0","prettier":"^1.16.4"},"scripts":{"lint":"eslint .","lint:fix":"eslint . --fix"},"gitHead":"d8b6fd3f4f033434eb0f7ef7bb631ec08e676312","_id":"@doingitright/gatsby-plugin-flexsearch@2.0.0","_nodeVersion":"12.14.1","_npmVersion":"6.13.4","dist":{"integrity":"sha512-4NcJiwf4/nUboXEXRT82SJv/Kz8jPQMQv0Hd7KdZAyBninsRfjbD4ro9UuBE9jwd2WmQnvoRuPbFAblyVdZKKw==","shasum":"06a471e7ec04ef8f7b69413c60215465ad723280","tarball":"https://registry.npmjs.org/@doingitright/gatsby-plugin-flexsearch/-/gatsby-plugin-flexsearch-2.0.0.tgz","fileCount":10,"unpackedSize":91806,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeQDuPCRA9TVsSAnZWagAAWsUP/04qdbgnwgqAwvxUA6Jr\ns5litOB14rD4P7PYBE98Xf79CRe72CTCpX58nA1IYvmUyoyPqfKyDE6VcD4X\nFBW3Mo0mZUZA9t0WwR3tQTSNoTqNH2DeMqk1A+JYG0zGiAeMF51iSLPgfpvk\nkqaJHSToCufyr9xdd8o0rvu2IZDZu1KYpfX+8z1pEbyqbCDHLrcderQweOi/\ns/eZL397bJxzv8gr+xrvhoLvqVEAvaS09mDmGjPuRAH6NAfCFwrYO2kNg5MH\nuv+YpmHyNYAJ1iOHmhBvx48rEsnhsdxicKd7X4cukgZdL5uV5pXpDdiVEzi9\nygxGKzz8yUBiClrdjEmb490xoo2cOI8R8ZUCXuM1XG+nOlCBUe2XHKfcYFyn\noVCbzcVIxpZUksP4pf2+s7YuZduuhXkdJFrtBO3y4yNihjV7kN8yoWpFQjZ2\neBb0AclnVXNTbfF9jUey0dn58re/j/+M8zF1IIQkix2nmyeBhCxJjAH3MNtW\ncMgjRdfjDe4oLKFYbubzmmNkXNKHokm795GVd8C7mOpHvQsipgtDQItXqeFF\npwpXZb5/508l8y4+GlShhqMo/OpwqcWByNRBTK+dxyAe37/yP0nm35vrwmzX\n3b0nijQOqm/9anOy4pI+9JjUmtfbo3pW/j6gECG5pTzqYsj2SXdSvbH8NCyq\njVr4\r\n=GplJ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFKt5U1WiVdWid0RI2ptV33rFfbs+X5cXB8/n5mQu/3UAiEA80hV/4ak8h2gSwpmyFerp0vsN4u3bx2pBuPFn8S8Sg8="}]},"maintainers":[{"name":"brandonfancher","email":"brandonfancher@gmail.com"}],"_npmUser":{"name":"brandonfancher","email":"brandonfancher@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/gatsby-plugin-flexsearch_2.0.0_1581267855361_0.41099001559540294"},"_hasShrinkwrap":false}},"time":{"created":"2020-02-09T17:04:15.024Z","2.0.0":"2020-02-09T17:04:15.505Z","modified":"2022-04-05T05:06:49.426Z"},"maintainers":[{"name":"brandonfancher","email":"brandonfancher@gmail.com"}],"description":"Search for Gatsby.js using FlexSearch.js","homepage":"https://github.com/brandonfancher/gatsby-plugin-flexsearch#readme","keywords":["gatsby","gatsby-plugin","search","flexsearch"],"contributors":[{"name":"Tiago Santos"},{"name":"Brandon Fancher","email":"brandonfancher@gmail.com","url":"http://brandonfancher.com"}],"author":{"name":"Tiago Santos"},"license":"MIT","readme":"# Flexsearch.js Plugin for Gatsby\n\nGatsby plugin for full text search implementation based on [FlexSearch.js](https://github.com/nextapps-de/flexsearch) client-side index, heavily inspired in the [gatsby-plugin-lunr](https://github.com/humanseelabs/gatsby-plugin-lunr).\n\n## Getting Started\n\nInstall `gatsby-plugin-flexsearch`\n\n`npm install --save gatsby-plugin-flexsearch`\n\nAdd `gatsby-plugin-flexsearch` configuration to the `gatsby-config.js` as following:\n\n```javascript\nmodule.exports = {\n    plugins: [\n        {\n      resolve: 'gatsby-plugin-flexsearch',\n      options: {\n        // L\n        languages: ['en'],\n        type: 'MarkdownRemark', // Filter the node types you want to index\n        // Fields to index.\n        fields: [\n          {\n            name: 'title',\n            indexed: true, // If indexed === true, the field will be indexed.\n            resolver: 'frontmatter.title',\n            // Attributes for indexing logic. Check https://github.com/nextapps-de/flexsearch#presets for details.\n            attributes: {\n              encode: 'balance',\n              tokenize: 'strict',\n              threshold: 6,\n              depth: 3,\n            },\n            store: true, // In case you want to make the field available in the search results.\n          },\n          {\n            name: 'description',\n            indexed: true,\n            resolver: 'frontmatter.description',\n            attributes: {\n              encode: 'balance',\n              tokenize: 'strict',\n              threshold: 6,\n              depth: 3,\n            },\n            store: false,\n          },\n          {\n            name: 'url',\n            indexed: false,\n            resolver: 'fields.slug',\n            store: true,\n          },\n        ],\n      },\n    },\n```\n\n## Implementing Search in Your UI\n\nThe search data will be available on the client side via `window.__FLEXSEARCH__` that is an object with the following fields:\n\n-   `index` - a flexsearch index instance\n-   `store` - object that stores the indexed gatsby nodes where the id of each node corresponds to the id the filter, according with flexsearch.js best practices (<https://github.com/nextapps-de/flexsearch#best-practices>)).\n\n```javascript\nimport React, { Component } from 'react'\nimport { Link } from 'gatsby'\n\n// Search component\nclass Search extends Component {\n  state = {\n    query: '',\n    results: [],\n  }\n\n  render() {\n    const ResultList = () => {\n      if (this.state.results.length > 0) {\n        return this.state.results.map((page, i) => (\n          <div className=\"item-search\" key={i}>\n            <Link to={page.url} className=\"link\">\n              <h4>{page.title}</h4>\n            </Link>\n          </div>\n        ))\n      } else if (this.state.query.length > 2) {\n        return 'No results for ' + this.state.query\n      } else if (\n        this.state.results.length === 0 &&\n        this.state.query.length > 0\n      ) {\n        return 'Please insert at least 3 characters'\n      } else {\n        return ''\n      }\n    }\n\n    return (\n      <div className={this.props.classNames}>\n        <input\n          className=\"search__input\"\n          type=\"text\"\n          onChange={this.search}\n          placeholder={'Search'}\n        />\n        <div className=\"search__list\">\n          <ResultList />\n        </div>\n      </div>\n    )\n  }\n\n  getSearchResults(query) {\n    // adicionar variável para língua\n    var index = window.__FLEXSEARCH__.en.index\n    var store = window.__FLEXSEARCH__.en.store\n    if (!query || !index) {\n      return []\n    } else {\n      var results = []\n      // search the indexed fields\n      Object.keys(index).forEach(idx => {\n        results.push(...index[idx].values.search(query)) // more search options at https://github.com/nextapps-de/flexsearch#index.search\n      })\n\n      // find the unique ids of the nodes\n      results = Array.from(new Set(results))\n\n      // return the corresponding nodes in the store\n      var nodes = store\n        .filter(node => (results.includes(node.id) ? node : null))\n        .map(node => node.node)\n\n      return nodes\n    }\n  }\n\n  search = event => {\n    const query = event.target.value\n    if (this.state.query.length > 2) {\n      const results = this.getSearchResults(query)\n      this.setState({ results: results, query: query })\n    } else {\n      this.setState({ results: [], query: query })\n    }\n  }\n}\n\nexport default Search\n```\n","readmeFilename":"README.md"}