Built by

hubelia

Category

Search

Version

0.0.1

Last updated

Jun 20, 2023, 14:44:43 PM8 months ago

MeiliSearch

* This is a WIP, and not toroughly tested.
Provide powerful indexing and searching features in your commerce application with MeiliSearch.

Features

  • Flexible configurations for specifying searchable and retrievable attributes.
  • Ready-integration with Medusa's Next.js starter storefront.
  • Utilize MeiliSearch's powerful search functionalities including typo-tolerance, synonyms, filtering, and more.

Prerequisites


How to Install

1. Run the following command in the directory of the Medusa backend:
npm install medusa-plugin-meilisearch-multi-indexes
2. Set the following environment variables in
Copy to clipboard
.env
:
MEILISEARCH_HOST=<YOUR_MEILISEARCH_HOST>
MEILISEARCH_API_KEY=<YOUR_MASTER_KEY>
3. In
Copy to clipboard
medusa-config.js
add the following at the end of the
Copy to clipboard
plugins
array:
const plugins = [
// ...
{
resolve: `medusa-plugin-meilisearch-multi-indexes`,
options: {
config: {
host: process.env.MEILISEARCH_HOST,
apiKey: process.env.MEILISEARCH_API_KEY,
},
settings: {
products: {
indexSettings: {
searchableAttributes: [
"title",
"description",
"variant_sku",
],
displayedAttributes: [
"title",
"description",
"variant_sku",
"thumbnail",
"handle",
],
},
primaryKey: "id",
transformer: (container, product) => ({
id: product.id,
// other attributes...
}),
documents: (container, documents) => ({
id: product.id,
// other attributes...
})
},
other_index: {
indexSettings: {
searchableAttributes: [
"title",
"description",
"variant_sku",
],
displayedAttributes: [
"title",
"description",
"variant_sku",
"thumbnail",
"handle",
],
},
primaryKey: "id",
transformer: (container, product) => ({
id: product.id,
// other attributes...
}),
documents: (container, documents) => {
// Here you can use the container or any sources to fetch documents
// and return the list of documents that will be added to the indexes.
// You can also transform the documents here if needed - or use the transformer
// to do so.
}
},
},
},
},
]

Test the Plugin

1. Run the following command in the directory of the Medusa backend to run the backend:
npm run start
2. Try searching products either using your storefront or using the Store APIs.

Additional Resources

Build your own plugins

Develop your own plugins with our API to speed up your processes.

Make your plugin available via npm for it to be shared in our Plugin Library with the broader Medusa community.