• Stars
    star
    208
  • Rank 182,176 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 3 years ago
  • Updated 28 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A strapi plugin to add your collections to Meilisearch

Meilisearch-Strapi

Meilisearch Strapi Plugin

Meilisearch | Meilisearch Cloud | Documentation | Discord | Roadmap | Website | FAQ

npm version Tests Prettier License Bors enabled

The Meilisearch plugin for Strapi

Meilisearch is an open-source search engine. Discover what Meilisearch is!

Add your Strapi content-types into a Meilisearch instance. The plugin listens to modifications made on your content-types and updates Meilisearch accordingly.

Table of Contents

📖 Documentation

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

To understand Strapi and how to create an app, see Strapi's documentation.

⚡ Supercharge your Meilisearch experience

Say goodbye to server deployment and manual updates with Meilisearch Cloud. Get started with a 14-day free trial! No credit card required.

🔧 Installation

This package version works with the v4 of Strapi. If you are using Strapi v3, please refer to this README.

Inside your Strapi app, add the package:

With npm:

npm install strapi-plugin-meilisearch

With yarn:

yarn add strapi-plugin-meilisearch

To apply the plugin to Strapi, a re-build is needed:

strapi build

You will need both a running Strapi app and a running Meilisearch instance. For specific version compatibility see this section.

🏃‍♀️ 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

🏃‍♂️ Run Strapi

If you don't have a running Strapi project yet, you can either launch the playground present in this project or create a Strapi project.

We recommend indexing your content-types to Meilisearch in development mode to allow the server reloads needed to apply or remove listeners.

strapi develop
// or
yarn develop

Run Both with Docker

To run Meilisearch and Strapi on the same server you can use Docker. A Docker configuration example can be found in the directory resources/docker of this repository.

To run the Docker script add both files Dockerfile and docker-compose.yaml at the root of your Strapi project and run it with the following command: docker-compose up.

🎬 Getting Started

Now that you have installed the plugin, a running meiliSearch instance and, a running Strapi app, let's go to the plugin page on your admin dashboard.

On the left-navbar, Meilisearch appears under the PLUGINS category. If it does not, ensure that you have installed the plugin and re-build Strapi (see installation).

🤫 Add Credentials

First, you need to configure credentials via the Strapi config, or on the plugin page. The credentials are composed of:

  • The host: The url to your running Meilisearch instance.
  • The api_key: The master or private key as the plugin requires administration permission on Meilisearch.More about permissions here.

⚠️ The master or private key should never be used to search on your front end. For searching, use the public key available on the key route.

Using the plugin page

You can add your Meilisearch credentials in the settings tab on the Meilisearch plugin page.

For example, using the credentials from the section above: Run Meilisearch, the following screen shows where the information should be.

Add your credentials

Once completed, click on the add button.

Using a config file

To use the Strapi config add the following to config/plugins.js:

// config/plugins.js

module.exports = () => ({
  //...
  meilisearch: {
    config: {
      // Your meili host
      host: "http://localhost:7700",
      // Your master key or private key
      apiKey: "masterKey",
    }
  }
})

Note that if you use both methods, the config file overwrites the credentials added through the plugin page.

🚛 Add your content-types to Meilisearch

If you don't have any content-types yet in your Strapi Plugin, please follow Strapi quickstart.

We will use, as example, the content-types provided by Strapi's quickstart (plus the user content-type).

On your plugin homepage, you should have two content-types appearing: restaurant, category and user.

Content-types

By clicking on the left checkbox, the content-type is automatically indexed in Meilisearch. For example, if you click on the restaurant checkbox, the indexing to Meilisearch starts.

Content-types

Once the indexing is done, your restaurants are in Meilisearch. We will see in start searching how to try it out.

🪝 Apply Hooks

Hooks are listeners that update Meilisearch each time you add/update/delete an entry in your content-types. They are activated as soon as you add a content-type to Meilisearch. For example by clicking on the checkbox of restaurant.

Nonetheless, if you remove a content-type from Meilisearch by unchecking the checkbox, you need to reload the server. If you don't, actions are still listened to and applied to Meilisearch. The reload is only possible in develop mode; click on the Reload Server button. If not, reload the server manually!

Remove hook from content-type

💅 Customization

It is possible to add settings for every collection. Start by creating a sub-object with the name of the collection inside your plugin.json file.

// config/plugins.js

module.exports = () => ({
  //...
  meilisearch: {
    config: {
      restaurant: {}
    }
  }
})

Settings:

🏷 Custom index name

By default, when indexing a content-type in Meilisearch, the index in Meilisearch has the same name as the content-type. This behavior can be changed by setting the indexName property in the configuration file of the plugin.

Example:

In the following example, the restaurant content-type in Meilisearch is called my_restaurant instead of the default restaurant.

// config/plugins.js

module.exports = () => ({
  //...
  meilisearch: {
    config: {
      restaurant: {
        indexName: "my_restaurants",
      }
    }
  }
})

It is possible to bind multiple content-types to the same index. They all have to share the same indexName.

For example if shoes and shirts should be bound to the same index, they must have the same indexName in the plugin configuration:

// config/plugins.js

module.exports = () => ({
  //...
  meilisearch: {
    config: {
      shirts: {
        indexName: 'products',
      },
      shoes: {
        indexName: 'products',
      },
    },
  },
})

Now, on each entry addition from both shoes and shirts the entry is added in the product index of Meilisearch.

disclaimer

Nonetheless, it is not possible to know how many entries from each content-type is added to Meilisearch.

For example, given two content-types:

  • Shoes: with 300 entries and an indexName set to product
  • Shirts: 200 entries and an indexName set to product

The index product has both the entries of shoes and shirts. If the index product has 350 documents in Meilisearch, it is not possible to know how many of them are from shoes or shirts.

When removing shoes or shirts from Meilisearch, both are removed as it would require to much processing to only remove one. You can still re-index only one after that.

Example with two single types:

Example of two content-types with same indexName

Examples can be found this directory.

🪄 Transform entries

By default, the plugin sent the data the way it is stored in your Strapi content-type. It is possible to remove or transform fields before sending your entries to Meilisearch.

Create the alteration function transformEntry in the plugin's configuration file. Before sending the data to Meilisearch, every entry passes through this function where the alteration is applied.

transformEntry can be synchronous or asynchronous.

You can find a lot of examples in this directory.

Example

For example, the restaurant content-type has a relation with the category content-type. Inside a restaurant entry the categories field contains an array of each category in an object format: [{ name: "Brunch" ...}, { name: "Italian ... }].

The following transforms categories in an array of strings containing only the name of the category:

// config/plugins.js

module.exports = {
  meilisearch: {
    config: {
      restaurant: {
        transformEntry({ entry }) { // can also be async
          return {
            ...entry,
            categories: entry.categories.map(category => category.name)
          }
        },
      }
    }
  },
}

Result:

  {
    "id": 2,
    "name": "Squared Pizza",
    "categories": [
      "Brunch",
      "Italian"
    ],
    // other fields
  }

By transforming the categories into an array of names, it is now compatible with the filtering feature in Meilisearch.

Important: You should always return the id of the entry without any transformation to allow sync when unpublished or deleting some entries in Strapi.

🤚 Filter entries

You might want to filter out some entries. This is possible with the filterEntry. Imagine you don't like Alfredo's restaurant. You can filter out this specific entry.

filterEntry can be synchronous or asynchronous.

// config/plugins.js

module.exports = {
  meilisearch: {
    config: {
      restaurant: {
        filterEntry({ entry }) { // can also be async
          return entry.title !== `Alfredo`
        },
      },
    },
  },
}

Alfredo's restaurant is not added to Meilisearch.

🏗 Add Meilisearch settings

Each index in Meilisearch can be customized with specific settings. It is possible to add your Meilisearch settings configuration to the indexes you create using the settings field in the plugin configuration file.

The settings are added when either: adding a content-type to Meilisearch or when updating a content-type in Meilisearch. The settings are not updated when documents are added through the listeners.

For example

module.exports = {
  meilisearch: {
    config: {
      restaurant: {
        settings: {
          filterableAttributes: ['categories'],
          synonyms: {
            healthy: ['pokeball', 'vegan']
          }
        }
      }
    }
  },
}

See resources for more settings examples.

🔎 Entries query

When indexing a content type to Meilisearch, the plugin has to fetch the documents from your database. With entriesQuery it is possible to specify some options are applied during the fetching of the entries. The options you can set are described in the findMany documentation of Strapi. However, we do not accept any changes on the start parameter.

Common use cases

If you are using the 🌍 Internationalization (i18n) plugin, an additional field locale can also be added in entriesQuery.

If you want to add a collection with a relation to the collection being included, you have to configure the populate parameter in entriesQuery. See the docs on how it works, and an example in our resources.

Example

If you want your documents to be fetched in batches of 1000 you specify it in the entriesQuery option.

module.exports = {
  meilisearch: {
    config: {
      restaurant: {
        entriesQuery: {
          limit: 1000
        }
      }
    }
  },
}

See resources for more entriesQuery examples.

🕵️‍♀️ Start Searching

Once you have a content-type indexed in Meilisearch, you can start searching.

To search in Meilisearch, you can use the instant-meilisearch library that integrates a whole search interface, or our meilisearch-js SDK.

⚡️ Using Instant meiliSearch

You can have a front up and running in record time with instant-meilisearch.

Restaurant demo

In Instant Meilisearch, you only have to provide your credentials and index name (uid). restaurant is the index name in our example.

You can have a quick preview with the following code in an HTML file. Create an HTML file, copy-paste the code below and open the file in your browser (or find it in /front_examples/restaurant.html).

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@meilisearch/instant-meilisearch/templates/basic_search.css" />
  </head>
  <body>
    <div class="wrapper">
      <div id="searchbox" focus></div>
      <div id="hits"></div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/@meilisearch/instant-meilisearch/dist/instant-meilisearch.umd.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/instantsearch.js@4"></script>
    <script>
        const search = instantsearch({
            indexName: "restaurant",
            searchClient: instantMeiliSearch(
                "http://localhost:7700",
                'publicKey', // Use the public key not the private or master key to search.
            )
            });

            search.addWidgets([
              instantsearch.widgets.searchBox({
                  container: "#searchbox"
              }),
              instantsearch.widgets.configure({ hitsPerPage: 8 }),
              instantsearch.widgets.hits({
                  container: "#hits",
                  templates: {
                  item: `
                      <div>
                      <div class="hit-name">
                          {{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}}
                      </div>
                      </div>
                  `
                  }
              })
            ]);
            search.start();
    </script>
  </body>
</html>

💛 Using Meilisearch for JS

You can also use meilisearch-js to communicate with Meilisearch.

The following code is a setup that will output a restaurant after a search.

import { MeiliSearch } from 'meilisearch'

;(async () => {
  const client = new MeiliSearch({
    host: 'http://127.0.0.1:7700',
    apiKey: 'publicKey', // Use the public key not the private or master key to search.
  })

  // An index is where the documents are stored.
  const response = client.index('movies').search('Biscoutte')
})()

response content:

{
  "hits": [
    {
      "id": 3,
      "name": "Biscotte Restaurant",
      "description": "Welcome to Biscotte restaurant! Restaurant Biscotte offers a cuisine based on fresh, quality products, often local, organic when possible, and always produced by passionate producers.",
      "categories": []
    }
  ],
  "offset": 0,
  "limit": 20,
  "nbHits": 1,
  "exhaustiveNbHits": false,
  "processingTimeMs": 1,
  "query": "biscoutte"
}

💡 Run the Playground

Instead of adding the plugin to an existing project, you can try it out using the playground in this project.

# Root of repository
yarn playground:build # Build the playground
yarn playground:dev # Start the development server

This command will install the required dependencies and launch the app in development mode. You should be able to reach it on the port 8000 of your localhost.

🤖 Compatibility with Meilisearch and Strapi

Supported Strapi versions:

Complete installation requirements are the same as for Strapi itself and can be found in the documentation under installation Requirements.

  • Strapi >=v4.x.x

If you are using Strapi v3, please refer to this README.

Supported Meilisearch versions:

This package guarantees compatibility with version v1.x of Meilisearch, but some features may not be present. Please check the issues for more info.

Node / NPM versions:

  • NodeJS >= 14.10 <= 16
  • NPM >= 6.x

We recommend always using the latest version of Strapi 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!

🌎 Community support

🤩 Just for the pleasure of the eyes

Using the foodadvisor restaurant demo Strapi provided. We added a searchbar to it using instant-meilisearch.

Fooradvisor demo

More Repositories

1

meilisearch

A lightning-fast search API that fits effortlessly into your apps, websites, and workflow
Rust
43,248
star
2

meilisearch-js

JavaScript client for the Meilisearch API
TypeScript
672
star
3

meilisearch-php

PHP wrapper for the Meilisearch API
PHP
543
star
4

meilisearch-laravel-scout

MeiliSearch integration for Laravel Scout
PHP
467
star
5

milli

Search engine library for Meilisearch ⚡️
Rust
459
star
6

meilisearch-js-plugins

The search client to use Meilisearch with InstantSearch.
TypeScript
449
star
7

meilisearch-go

Golang wrapper for the Meilisearch API
Go
444
star
8

heed

A fully typed LMDB wrapper with minimum overhead 🐦
Rust
424
star
9

meilisearch-python

Python wrapper for the Meilisearch API
Python
400
star
10

MeiliES

A Rust based event store using the Redis protocol
Rust
326
star
11

meilisearch-rust

Rust wrapper for the Meilisearch API.
Rust
316
star
12

meilisearch-rails

Meilisearch integration for Ruby on Rails
Ruby
273
star
13

docs-scraper

Scrape documentation into Meilisearch
Python
257
star
14

meilisearch-dotnet

.NET wrapper for the Meilisearch API
C#
232
star
15

mini-dashboard

mini-dashboard for Meilisearch
JavaScript
204
star
16

charabia

Library used by Meilisearch to tokenize queries and documents
Rust
202
star
17

meilisearch-ruby

Ruby SDK for the Meilisearch API
Ruby
186
star
18

meilisearch-react

182
star
19

meilisearch-kubernetes

Meilisearch on Kubernetes Helm charts and manifests
Mustache
181
star
20

arroy

Annoy-inspired Approximate Nearest Neighbors in Rust, based on LMDB and optimized for memory usage 💥
Rust
170
star
21

meilisearch-java

Java client for Meilisearch
Java
163
star
22

docs-searchbar.js

Front-end search bar for documentation with Meilisearch
JavaScript
161
star
23

meilisearch-vue

148
star
24

documentation

Meilisearch documentation
MDX
132
star
25

integration-guides

Central reference for Meilisearch integrations.
Shell
127
star
26

meilisearch-symfony

Seamless integration of Meilisearch into your Symfony project.
PHP
111
star
27

awesome-meilisearch

A curated list of awesome Meilisearch resources
88
star
28

meilisearch-swift

Swift client for the Meilisearch API
Swift
87
star
29

firestore-meilisearch

Fulltext search on Firebase with Meilisearch
TypeScript
83
star
30

meilisearch-dart

The Meilisearch API client written for Dart
Dart
73
star
31

ecommerce-demo

Nuxt 3 ecommerce site search with filtering and facets powered by Meilisearch
Vue
73
star
32

vuepress-plugin-meilisearch

Add a relevant and typo tolerant search bar to your VuePress
JavaScript
62
star
33

saas-demo

App search in a CRM use case, powered by Meilisearch
PHP
58
star
34

product

Public feedback and ideation discussions for Meilisearch product 🔮
55
star
35

meilisearch-wordpress

WordPress plugin for Meilisearch.
PHP
53
star
36

demos

A list of Meilisearch demos with open-source code and live preview ⚡️
CoffeeScript
43
star
37

gatsby-plugin-meilisearch

A plugin to index your Gatsby content to Meilisearch based on graphQL queries
JavaScript
40
star
38

demo-movies

A website that lets you know where to watch a movie
JavaScript
34
star
39

landing

Meilisearch's landing page
JavaScript
33
star
40

meilisearch-migration

Scripts to update Meilisearch version's.
Shell
32
star
41

devrel

Anything Developer Relations at Meili
CSS
27
star
42

meilisearch-digitalocean

Meilisearch services on DigitalOcean
Python
24
star
43

meilisearch-angular

Instant Meilisearch for Angular Framework
23
star
44

deserr

Deserialization library with focus on error handling
Rust
22
star
45

meilisearch-aws

AWS services for Meilisearch
Python
20
star
46

cargo-flaky

A cargo sub-command to helps you find flaky tests
Rust
20
star
47

meilisearch-gcp

Meilisearch services on GCP
Python
20
star
48

grenad

Tools to sort, merge, write, and read immutable key-value pairs 🍅
Rust
19
star
49

specifications

Track specification elaboration.
18
star
50

madness

an async mdns library for tokio
Rust
17
star
51

demo-finding-crates

Expose all crates from crates.io with MeiliSearch
Rust
17
star
52

scrapix

TypeScript
16
star
53

transplant

Rust
15
star
54

cloud-providers

☁ Meilisearch DevOps Tools for the Cloud ☁
Shell
15
star
55

engine-team

Repository gathering the development process of the core-team
13
star
56

meilisearch-importer

A CLI to import massive CSV and NdJson into Meilisearch
Rust
12
star
57

compute-embeddings

A small tool to compute the embeddings of a list of JSON documents
Rust
10
star
58

cloud-scripts

Cloud scripts for cloud provider agnostic configuration
Shell
9
star
59

demo-finding-rubygems

Alternative search bar for RubyGems
Ruby
8
star
60

minimeili-raft

A small implementation of a dummy Meilisearch running on top of Raft
Rust
7
star
61

demo-MoMA

A MeiliSearch demo using the Museum Of Modern Art Collection
JavaScript
6
star
62

strapi-plugin-meilisearch-v4

Work in progress
JavaScript
6
star
63

searchbar.js

wip
JavaScript
6
star
64

meili-aoc

meili-aoc
Rust
5
star
65

mini-search-engine-presentation

A simple and "short" presentation of the search engine
5
star
66

vercel-demo

A website that lets you know where to watch a movie built on Next.js and Meilisearch, deployed on Vercel with the Meilisearch + Vercel integration.
JavaScript
5
star
67

meilisearch-flutter

[wip] A basic UI kit with Meilisearch search widgets for Flutter
CMake
4
star
68

jayson

Rust
4
star
69

nelson

Rust
4
star
70

demo-finding-pypi

Alternative search bar for PyPI packages
Python
4
star
71

nextjs-starter-meilisearch-table

TypeScript
3
star
72

js-project-boilerplate

A boilerplate providing basic configuration for JavaScript projects in Meilisearch
3
star
73

synonyms

2
star
74

devops-tools

Shell
2
star
75

discord-bot-productboard

JavaScript
2
star
76

strois

A simple non-async S3 client based on the REST API
Rust
2
star
77

datasets

2
star
78

poc-vector-store-recall

A experimental tool that uses the vector store to increase Meilisearch's recall
Rust
2
star
79

.github

1
star
80

actions

Meilisearch Github Actions
JavaScript
1
star
81

devspector

Develop specification inspector
JavaScript
1
star
82

design-team

1
star
83

movies-react-demo

Created with CodeSandbox
HTML
1
star
84

ansible-vm-benchmarks

Ansible Playbook to index datasets on several typology of Instance on a specific Meilisearch version/commit
Rust
1
star
85

akamai-purge

A Rust helper to purge Akamai cache
Rust
1
star
86

poc-heed-codec

A repository to help us define the new design of heed
Rust
1
star
87

mainspector

Main specification inspector
JavaScript
1
star
88

settings_guessr

A tool that guess your settings by using the dataset
Rust
1
star
89

meilisearch-webhook-usage-example

Example of how to use the meilisearch webhook
Rust
1
star
90

meilikeeper

A sync zookeeper client on top of the official C client
Rust
1
star
91

massive-meilisearch-sampling

A program that generates and sends dataset and samples update/deletes to a Meilisearch server
Rust
1
star
92

zookeeper-client-sync

zookeeper-client-sync
Rust
1
star