Skip to content

A plugin to index your Gatsby content to MeiliSearch based on graphQL queries

License

Notifications You must be signed in to change notification settings

ferdi05/gatsby-plugin-meilisearch

 
 

Repository files navigation

MeiliSearch Gatsby

Gatsby plugin MeiliSearch

Bors enabled Tests License


A plugin to index your Gatsby content to MeiliSearch based on graphQL queries


Table of Contents

📖 Documentation

To understand MeiliSearch and how it works, see the MeiliSearch's documentation.

To understand Gatsby and how it works, see Gatsby's documentation.

🔧 Installation

Inside your Gatsby app, add the package:

With npm:

npm install gatsby-plugin-meilisearch

With yarn:

yarn add gatsby-plugin-meilisearch

🏃‍♀️ Run MeiliSearch

There are many easy ways to download and run a MeiliSearch instance.

For example, if you use Docker:

docker pull getmeili/meilisearch:latest # Fetch the latest version of MeiliSearch image from Docker Hub
docker run -it --rm -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --master-key=masterKey

🎬 Usage

Basic

gatsby-config.js

{
  resolve: 'gatsby-plugin-meilisearch',
  options: {
    // Host on which your MeiliSearch instance is running
    host: 'http://localhost:7700',
    indexes: [
      {
        // Index in which the content will be added
        indexUid: `my_blog`,
        // Function that transforms the fetched data before sending it to MeiliSearch
        transformer: data => data.allMdx.edges.map(({ node }) => node),
        // graphQL query that fetches the data to index in MeiliSearch
        query: `
          query MyQuery {
            allMdx {
              edges {
                node {
                  id
                  slug
                  frontmatter {
                    title
                    cover
                  }
                  tableOfContents
                }
              }
            }
          }
        `,
      }
    ],
  },
}

Customization

The plugin accepts the following options for further customization :

{
  resolve: 'gatsby-plugin-meilisearch',
  options: {
    apiKey: "masterKey", // API key if the MeiliSearch instance is password protected
    skipIndexing: true, // Run script without indexing to MeiliSearch. Default to false
    batchSize: 1000, // The number of documents that should be included in each batch. Default to 1000
    settings: {
      searchableAttributes: ['title'], // MeiliSearch's settings. See https://docs.meilisearch.com/reference/features/settings.html
    },
  },
}

🤖 Compatibility with MeiliSearch and Gatsby

Supported Gatsby versions:

  • Gastby v4.3.x

(This plugin may work with the older Gatsby versions, but these are not tested nor officially supported at this time.)

Supported MeiliSearch versions:

This package only guarantees the compatibility with the version v0.24.0 of MeiliSearch.

Node / NPM versions:

  • NodeJS >= 14.15.X && <= 16.X
  • NPM >= 6.x

We recommend always using the latest version of Gatsby to start your new projects.

⚙️ Development Workflow and Contributing

Any new contribution is more than welcome in this project!

If you want to know more about the development workflow or want to contribute, please visit our contributing guidelines for detailed instructions!

About

A plugin to index your Gatsby content to MeiliSearch based on graphQL queries

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 98.7%
  • Shell 1.3%