npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mattiebelt/strapi-plugin-meilisearch

v0.4.2

Published

Synchronise and search in your Strapi collections with MeiliSearch

Downloads

2

Readme

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

Add your Strapi collections into a MeiliSearch instance. The plugin listens to modifications made on your collections 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.

🔧 Installation

Inside your Strapi app, add the package:

With npm:

npm install strapi-plugin-meilisearch@npm:@mattiebelt/strapi-plugin-meilisearch

With yarn:

yarn add strapi-plugin-meilisearch@npm:@mattiebelt/strapi-plugin-meilisearch

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

strapi build --clean

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 adding your collections in development mode to allow the server reloads needed to apply hooks.

strapi develop
// or
yarn develop

🎬 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. Add the following to config/plugins.js or config/[NODE_ENV]/plugin.js (docs):

module.exports = () => ({
  //...
  meilisearch: {
    // Your master key
    apiKey: "masterKey",
    // Your meili host
    host: "http://localhost:7700",
    // The collections you want to be indexed
    collections: [
        { name: 'project', index: 'global' }, // `index` is optional
        { name: 'category' },
        { name: 'page', index: 'global' }
      ]
  }
  //...
})

Using config/[NODE_ENV]/plugin.js, it is possible to have a config file for different environments.

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

🪝 Apply Hooks

Hooks are listeners that update MeiliSearch each time you add/update/delete an entry in your collections. To will load on a server (re)start.

🕵️‍♀️ Start Searching

Once you have a collection containing documents 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.

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"
            )
            });

            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: 'masterKey',
  })

  // 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:dev

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 v3.6.x

(This plugin may work with the older Strapi 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.20.0 of MeiliSearch.

Node / NPM versions:

  • NodeJS >= 12.10 <= 14
  • 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.