angeloashmore / gatsby-plugin-local-search

Gatsby plugin for providing client-side search for data available in Gatsby's GraphQL layer using a variety of engines
MIT License
51 stars 29 forks source link

Default: all fields #53

Closed corneliugaina closed 1 year ago

corneliugaina commented 2 years ago

In the gatsby-config example, it says for index and store there's an 'default' option to expose all fields. However it's not self-explanatory and I tried several options whitout success.

Anybody can explain how I can expose all the properties of normalizer without writing what fields should be in index and store ?

    // List of keys to index. The values of the keys are taken from the
    // normalizer function below.
    // Default: all fields
    index: ['title', 'body'],

    // List of keys to store and make available in your UI. The values of
    // the keys are taken from the normalizer function below.
    // Default: all fields
    store: ['id', 'path', 'title'],
nashvinxtn commented 1 year ago

Any news on this issue.

angeloashmore commented 1 year ago

Hey @corneliugaina and @nashvinxtn,

If you would like to index and/or store all fields, you can simply omit the option. If you don't specify a list of index or store keys, the lists will default to all keys.

Here is an example:

// gatsby-config.js

module.exports = {
  plugins: [

    {
      resolve: 'gatsby-plugin-local-search',
      options: {
        name: 'pages',
        engine: 'flexsearch',
        query: `
          {
            # Your query
          }
        `,
        normalizer: ({ data }) => {
          // Your normalizer
        }
      },
    },
  ],
}

Because the index and store options are not included, each of them will default to all of your keys. You can also choose to include just index or just store, or both.