1 ---
2 products:
3 - product
4 ---
5
6 import { Card, Note, Prerequisites, Details, WorkflowDiagram } from "docs-ui"
7 import { Github, PlaySolid } from "@medusajs/icons"
8
9 export const metadata = {
10 title: `Integrate Meilisearch with Medusa`,
11 }
12
13 # {metadata.title}
14
15 In this tutorial, you'll learn how to integrate Meilisearch with Medusa to enable advanced search capabilities in your storefront.
16
17 <Note title="Deprecated" type="warning">
18
19 This guide is deprecated as of Medusa v2.21.1, which introduced the [Search Module](/infrastructure-modules/search). Rather than the custom module this guide builds, consider one of the following instead:
20
21 - [Medusa Search](!cloud!/search), the managed search service for Cloud projects. Refer to [Medusa Search vs Meilisearch](!cloud!/search/meilisearch) for a comparison.
22 - A [Search Module Provider](/references/search/provider) for Meilisearch, which keeps Meilisearch behind the Search Module's index definitions and `query.search`.
23
24 If you already followed this guide, refer to [Migrate from Meilisearch to Medusa Search](!cloud!/search/migrate-from-meilisearch) for the migration steps.
25
26 </Note>
27
28 When you install a Medusa application, you get a fully-fledged commerce platform with a Framework for customization. Medusa's architecture supports integrating third-party services, such as search engines, allowing you to build custom features around core commerce flows.
29
30 [Meilisearch](https://www.meilisearch.com/) is an open-source, fast, and relevant search engine that you can integrate with Medusa to enhance your storefront's search functionality.
31
32 ## Summary
33
34 By following this tutorial, you'll learn how to:
35
36 - Install and set up Medusa.
37 - Integrate Meilisearch into Medusa.
38 - Trigger Meilisearch reindexing when a product is created, updated, or deleted, or when an admin manually triggers a reindex.
39 - Customize the Next.js Starter Storefront to search for products through Meilisearch.
40
41 You can follow this tutorial whether you're new to Medusa or an advanced Medusa developer.
42
43 ![Diagram illustrating the integration of Meilisearch with Medusa](https://res.cloudinary.com/dza7lstvk/image/upload/v1758091098/Medusa%20Resources/meilisearch-summary_bdig6e.jpg)
44
45 <Card
46 title="Example Repository"
47 text="Find the full code of the guide in this repository."
48 href="https://github.com/medusajs/examples/tree/main/meilisearch-integration"
49 icon={Github}
50 />
51
52 ---
53
54 ## Step 1: Install a Medusa Application
55
56 <Prerequisites items={[
57 {
58 text: "Node.js v20.19.0+ or v22.12.0+",
59 link: "https://nodejs.org/en/download"
60 },
61 {
62 text: "Git CLI tool",
63 link: "https://git-scm.com/downloads"
64 },
65 {
66 text: "PostgreSQL",
67 link: "https://www.postgresql.org/download/"
68 }
69 ]} />
70
71 Start by installing the Medusa application on your machine with the following command:
72
73 ```bash
74 npx create-medusa-app@latest
75 ```
76
77 You'll first be asked for the project's name. Then, when asked whether you want to install the [Next.js Starter Storefront](../../../nextjs-starter/page.mdx), choose "Yes."
78
79 Afterwards, the installation process will start, which will install the Medusa application as a monorepository in a directory with your project's name. The backend is installed in the `apps/backend` directory, and the Next.js Starter Storefront is installed in the `apps/storefront` directory.
80
81 Once the installation finishes successfully, the Medusa Admin dashboard will open with a form to create a new user. Enter the user's credentials and submit the form. Afterwards, you can log in with the new user and explore the dashboard.
82
83 <Note title="Ran into Errors">
84
85 Check out the [troubleshooting guides](../../../troubleshooting/create-medusa-app-errors/page.mdx) for help.
86
87 </Note>
88
89 <Note>
90
91 In this guide, all file paths of backend customizations are relative to the `apps/backend` directory of your Medusa project.
92
93 </Note>
94
95 ---
96
97 ## Step 2: Create Meilisearch Module
98
99 <Prerequisites
100 items={[
101 {
102 text: "Meilisearch instance (Cloud or local)",
103 link: "https://www.meilisearch.com/docs/learn/getting_started/cloud_quick_start"
104 }
105 ]}
106 />
107
108 To integrate third-party services into Medusa, you create a custom module. A module is a reusable package with functionalities related to a single feature or domain. Medusa integrates the module into your application without side effects on your setup.
109
110 In this step, you'll create a custom module that provides the necessary functionalities to integrate Meilisearch with Medusa.
111
112 <Note>
113
114 Refer to the [Modules documentation](!docs!/learn/fundamentals/modules) to learn more.
115
116 </Note>
117
118 Before building the module, you need to install Meilisearch's JavaScript client. Run the following command in your Medusa application's root directory:
119
120 ```bash npm2yarn
121 npm install meilisearch
122 ```
123
124 ### Create Module Directory
125
126 A module is created under the `src/modules` directory of your Medusa application. So, create the directory `src/modules/meilisearch`.
127
128 ### Create Service
129
130 You define a module's functionalities in a service. A service is a TypeScript or JavaScript class that the module exports. In the service's methods, you can connect to the database, which is useful if your module defines tables in the database, or connect to third-party services.
131
132 In this section, you'll create the Meilisearch Module's service and the methods necessary to manage indexed products in Meilisearch and search through them.
133
134 To create the Meilisearch Module's service, create the file `src/modules/meilisearch/service.ts` with the following content:
135
136 ```ts title="src/modules/meilisearch/service.ts"
137 const { Meilisearch } = require("meilisearch")
138 import { MedusaError } from "@medusajs/framework/utils"
139
140 type MeilisearchOptions = {
141 host: string;
142 apiKey: string;
143 productIndexName: string;
144 }
145
146 export type MeilisearchIndexType = "product"
147
148 export default class MeilisearchModuleService {
149 private client: typeof Meilisearch
150 private options: MeilisearchOptions
151
152 constructor({}, options: MeilisearchOptions) {
153 if (!options.host || !options.apiKey || !options.productIndexName) {
154 throw new MedusaError(
155 MedusaError.Types.INVALID_ARGUMENT,
156 "Meilisearch options are required"
157 )
158 }
159 this.client = new Meilisearch({
160 host: options.host,
161 apiKey: options.apiKey,
162 })
163 this.options = options
164 }
165
166 // TODO: Add methods
167 }
168 ```
169
170 You export a class that serves as the Meilisearch Module's service. In the service, you define two properties:
171
172 - `client`: An instance of the Meilisearch Client, which you'll use to perform actions with Meilisearch's API.
173 - `options`: An object of options that the module receives when it's registered, which you'll learn about later. The options contain:
174 - `apiKey`: The Meilisearch API key.
175 - `host`: The Meilisearch host.
176 - `productIndexName`: The name of the index where products are stored.
177
178 <Note title="Tip">
179
180 If you want to index other types of data, such as product categories, you can add new properties for their index names in the `MeilisearchOptions` type.
181
182 </Note>
183
184 A module's service receives the module's options as a second parameter in its constructor. In the constructor, you initialize the Meilisearch client using the module's options.
185
186 <Note title="What is the first constructor parameter?">
187
188 A module has a container that holds all resources registered in that module, and you can access those resources in the first parameter of the constructor. Learn more about it in the [Module Container documentation](!docs!/learn/fundamentals/modules/container).
189
190 </Note>
191
192 #### Index Data Method
193
194 The first method you need to add to the service is a method that receives an array of data to add or update in Meilisearch's index.
195
196 Add the following methods to the `MeilisearchModuleService` class:
197
198 ```ts title="src/modules/meilisearch/service.ts"
199 import { MedusaError } from "@medusajs/framework/utils"
200
201 export default class MeilisearchModuleService {
202 // ...
203 async getIndexName(type: MeilisearchIndexType) {
204 switch (type) {
205 case "product":
206 return this.options.productIndexName
207 default:
208 throw new MedusaError(
209 MedusaError.Types.INVALID_DATA,
210 `Invalid index type: ${type}`
211 )
212 }
213 }
214
215 async indexData(data: Record<string, unknown>[], type: MeilisearchIndexType = "product") {
216 const indexName = await this.getIndexName(type)
217 const index = this.client.index(indexName)
218
219 // Transform data to include id as primary key for Meilisearch
220 const documents = data.map((item) => ({
221 ...item,
222 id: item.id,
223 }))
224
225 await index.addDocuments(documents)
226 }
227 }
228 ```
229
230 You define two methods:
231
232 1. `getIndexName`: A method that receives an `MeilisearchIndexType` (defined in the previous snippet) and returns the index name for that type. In this case, you only have one type, `product`, so you return the product index name.
233 - If you want to index other types of data, you can add more cases to the switch statement.
234 2. `indexData`: A method that receives an array of data and an `MeilisearchIndexType`. The method indexes the data in the Meilisearch index for the given type.
235
236 ### Retrieve and Delete Methods
237
238 The next methods you'll add to the service are methods to retrieve and delete data from the Meilisearch index. You'll use these later to keep the Meilisearch index in sync with Medusa.
239
240 Add the following methods to the `MeilisearchModuleService` class:
241
242 ```ts title="src/modules/meilisearch/service.ts"
243 export default class MeilisearchModuleService {
244 // ...
245
246 async retrieveFromIndex(documentIds: string[], type: MeilisearchIndexType = "product") {
247 const indexName = await this.getIndexName(type)
248 const index = this.client.index(indexName)
249
250 const results = await Promise.all(
251 documentIds.map(async (id) => {
252 try {
253 return await index.getDocument(id)
254 } catch (error) {
255 // Document not found, return null
256 return null
257 }
258 })
259 )
260
261 return results.filter(Boolean)
262 }
263
264 async deleteFromIndex(documentIds: string[], type: MeilisearchIndexType = "product") {
265 const indexName = await this.getIndexName(type)
266 const index = this.client.index(indexName)
267
268 await index.deleteDocuments(documentIds)
269 }
270 }
271 ```
272
273 You define two methods:
274
275 1. `retrieveFromIndex`: A method that receives an array of document IDs and a `MeilisearchIndexType`. The method retrieves the documents with the given IDs from the Meilisearch index.
276 2. `deleteFromIndex`: A method that receives an array of document IDs and a `MeilisearchIndexType`. The method deletes the documents with the given IDs from the Meilisearch index.
277
278 #### Search Method
279
280 The last method you'll implement is a method to search through the Meilisearch index. This method lets you expose search functionality to clients through Medusa's API routes.
281
282 Add the following method to the `MeilisearchModuleService` class:
283
284 ```ts title="src/modules/meilisearch/service.ts"
285 export default class MeilisearchModuleService {
286 // ...
287
288 async search(query: string, type: MeilisearchIndexType = "product") {
289 const indexName = await this.getIndexName(type)
290 const index = this.client.index(indexName)
291
292 return await index.search(query)
293 }
294 }
295 ```
296
297 The `search` method receives a query string and a `MeilisearchIndexType`. The method searches through the Meilisearch index for the given type, such as products, and returns the results.
298
299
300 ### Export Module Definition
301
302 The final piece of a module is its definition, which you export in an `index.ts` file at its root directory. This definition tells Medusa the name of the module and its service.
303
304 So, create the file `src/modules/meilisearch/index.ts` with the following content:
305
306 ```ts title="src/modules/meilisearch/index.ts"
307 import { Module } from "@medusajs/framework/utils"
308 import MeilisearchModuleService from "./service"
309
310 export const MEILISEARCH_MODULE = "meilisearch"
311
312 export default Module(MEILISEARCH_MODULE, {
313 service: MeilisearchModuleService,
314 })
315 ```
316
317 You use the `Module` function from the Modules SDK to create the module's definition. It accepts two parameters:
318
319 1. The module's name, which is `meilisearch`.
320 2. An object with a required property `service` indicating the module's service.
321
322 You also export the module's name as `MEILISEARCH_MODULE` so you can reference it later.
323
324 ### Add Module to Medusa's Configurations
325
326 Once you finish building the module, add it to Medusa's configurations to start using it.
327
328 In `medusa-config.ts`, add a `modules` property and pass an array with your custom module:
329
330 ```ts title="medusa-config.ts"
331 module.exports = defineConfig({
332 // ...
333 modules: [
334 {
335 resolve: "./src/modules/meilisearch",
336 options: {
337 host: process.env.MEILISEARCH_HOST!,
338 apiKey: process.env.MEILISEARCH_API_KEY!,
339 productIndexName: process.env.MEILISEARCH_PRODUCT_INDEX_NAME!,
340 },
341 },
342 ],
343 })
344 ```
345
346 Each object in the `modules` array has a `resolve` property, whose value is either a path to the module's directory, or an `npm` package’s name.
347
348 You also pass an `options` property with the module's options, including the Meilisearch host, API Key, and the product index name.
349
350 ### Add Environment Variables
351
352 Before you can start using the Meilisearch Module, you need to set the environment variables for the Meilisearch host, API Key, and the product index name.
353
354 Add the following environment variables to your `.env` file:
355
356 ```env
357 MEILISEARCH_HOST=your-meilisearch-host
358 MEILISEARCH_API_KEY=your-meilisearch-api-key
359 MEILISEARCH_PRODUCT_INDEX_NAME=your-product-index-name
360 ```
361 - `your-meilisearch-host` is the host of your Meilisearch instance. If you're running Meilisearch locally, it should be `http://127.0.0.1:7700`.
362 - `your-meilisearch-api-key` is the master key of your Meilisearch instance. If you're running Meilisearch locally, you should have set it when starting Meilisearch. If you're using Meilisearch Cloud, you can find it in the dashboard under "API Keys." Learn more in the [Meilisearch documentation](https://www.meilisearch.com/docs/learn/security/basic_security).
363 - `your-product-index-name` is the name of the index where you'll store products. You can choose any name you want. Even if the index doesn't exist, Meilisearch will create it when you add documents to it.
364
365 Your module is now ready for use. You'll see how to use it in the next steps.
366
367 ---
368
369 ## Step 3: Sync Products to Meilisearch Workflow
370
371 To keep the Meilisearch index in sync with Medusa, you need to trigger indexing when products are created, updated, or deleted in Medusa. You can also allow admins to manually trigger a reindex.
372
373 To implement the indexing functionality, you need to create a [workflow](!docs!/learn/fundamentals/workflows). A workflow is a series of actions, called steps, that complete a task. You construct a workflow like you construct a function, but it's a special function that allows you to track its executions' progress, define roll-back logic, and configure other advanced features.
374
375 <Note>
376
377 Learn more about workflows in the [Workflows documentation](!docs!/learn/fundamentals/workflows).
378
379 </Note>
380
381 In this step, you'll create a workflow that indexes products in Meilisearch. In the next steps, you'll learn how to use the workflow when products are created, updated, or deleted, or when admins manually trigger a reindex.
382
383 The workflow has the following steps:
384
385 <WorkflowDiagram
386 workflow={{
387 name: "syncProductsWorkflow",
388 steps: [
389 {
390 type: "step",
391 name: "useQueryGraphStep",
392 description: "Retrieve products matching specified filters and pagination parameters.",
393 link: "/references/helper-steps/useQueryGraphStep",
394 depth: 1
395 },
396 {
397 type: "step",
398 name: "syncProductsStep",
399 description: "Index published products in Meilisearch.",
400 depth: 2
401 },
402 {
403 type: "step",
404 name: "deleteProductsFromMeilisearchStep",
405 description: "Delete unpublished products from Meilisearch.",
406 depth: 3
407 }
408 ]
409 }}
410 hideLegend
411 />
412
413 Medusa provides the `useQueryGraphStep` in its `@medusajs/medusa/core-flows` package. You only need to implement the other steps.
414
415 ### syncProductsStep
416
417 In the second step of the workflow, you create or update indexes in Meilisearch for the products retrieved in the first step.
418
419 To create the step, create the file `src/workflows/steps/sync-products.ts` with the following content:
420
421 <Note>
422
423 If you get a type error on resolving the Meilisearch Module, run the Medusa application once with the `npm run dev` or `yarn dev` command to generate the necessary type definitions, as explained in the [Automatically Generated Types guide](!docs!/learn/fundamentals/generated-types).
424
425 </Note>
426
427 ```ts title="src/workflows/steps/sync-products.ts"
428 import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
429 import { MEILISEARCH_MODULE } from "../../modules/meilisearch"
430 import MeilisearchModuleService from "../../modules/meilisearch/service"
431
432 export type SyncProductsStepInput = {
433 products: {
434 id: string
435 title: string
436 description?: string
437 handle: string
438 thumbnail?: string
439 categories: {
440 id: string
441 name: string
442 handle: string
443 }[]
444 tags: {
445 id: string
446 value: string
447 }[]
448 }[]
449 }
450
451 export const syncProductsStep = createStep(
452 "sync-products",
453 async ({ products }: SyncProductsStepInput, { container }) => {
454 const meilisearchModuleService = container.resolve<MeilisearchModuleService>(
455 MEILISEARCH_MODULE
456 )
457 const existingProducts = await meilisearchModuleService.retrieveFromIndex(
458 products.map((product) => product.id),
459 "product"
460 )
461 const newProducts = products.filter((product) => !existingProducts.some(
462 (p) => p.id === product.id)
463 )
464 await meilisearchModuleService.indexData(
465 products as unknown as Record<string, unknown>[],
466 "product"
467 )
468
469 return new StepResponse(undefined, {
470 newProducts: newProducts.map((product) => product.id),
471 existingProducts,
472 })
473 }
474 // TODO add compensation
475 )
476 ```
477
478 You create a step with `createStep` from the Workflows SDK. It accepts two parameters:
479
480 1. The step's unique name, which is `sync-products`.
481 2. An async function that receives two parameters:
482 - The step's input, which is an object holding an array of products to sync into Meilisearch.
483 - An object that has properties including the [Medusa container](!docs!/learn/fundamentals/medusa-container), which is a registry of Framework and commerce tools that you can access in the step.
484
485 In the step function, you resolve the Meilisearch Module's service from the Medusa container using the name you exported in the module definition's file.
486
487 Then, you retrieve the products that are already indexed in Meilisearch and determine which products are new. You'll learn why this is useful in a bit.
488
489 Finally, you pass the products you received in the input to Meilisearch to create or update its indices.
490
491 A step function must return a `StepResponse` instance. The `StepResponse` constructor accepts two parameters:
492
493 1. The step's output, which in this case is `undefined`.
494 2. Data to pass to the step's compensation function.
495
496 #### Compensation Function
497
498 The compensation function undoes the actions performed in a step. Then, if an error occurs during the workflow's execution, the compensation functions of executed steps are called to roll back the changes. This mechanism ensures data consistency in your application, especially as you integrate external systems.
499
500 To add a compensation function to a step, pass it as a third parameter to `createStep`:
501
502 ```ts title="src/workflows/steps/sync-products.ts"
503 export const syncProductsStep = createStep(
504 // ...
505 async (input, { container }) => {
506 if (!input) {
507 return
508 }
509
510 const meilisearchModuleService = container.resolve<MeilisearchModuleService>(
511 MEILISEARCH_MODULE
512 )
513
514 if (input.newProducts) {
515 await meilisearchModuleService.deleteFromIndex(
516 input.newProducts,
517 "product"
518 )
519 }
520
521 if (input.existingProducts) {
522 await meilisearchModuleService.indexData(
523 input.existingProducts,
524 "product"
525 )
526 }
527 }
528 )
529 ```
530
531 The compensation function receives two parameters:
532
533 1. The data you passed as a second parameter of `StepResponse` in the step function.
534 2. A context object similar to the step function that holds the Medusa container.
535
536 In the compensation function, you resolve the Meilisearch Module's service from the container. Then, you delete from Meilisearch the products that were newly indexed and revert the existing products to their original data.
537
538 #### deleteProductsFromMeilisearchStep
539
540 The `deleteProductsFromMeilisearchStep` step deletes products from Meilisearch when they are unpublished or deleted in Medusa.
541
542 Create the step at `src/workflows/steps/delete-products-from-meilisearch.ts` with the following content:
543
544 ```ts title="src/workflows/steps/delete-products-from-meilisearch.ts"
545 import {
546 createStep,
547 StepResponse,
548 } from "@medusajs/framework/workflows-sdk"
549 import { MEILISEARCH_MODULE } from "../../modules/meilisearch"
550
551 export type DeleteProductsFromMeilisearchStep = {
552 ids: string[]
553 }
554
555 export const deleteProductsFromMeilisearchStep = createStep(
556 "delete-products-from-meilisearch-step",
557 async (
558 { ids }: DeleteProductsFromMeilisearchStep,
559 { container }
560 ) => {
561 const meilisearchModuleService = container.resolve(MEILISEARCH_MODULE)
562
563 const existingRecords = await meilisearchModuleService.retrieveFromIndex(
564 ids,
565 "product"
566 )
567 await meilisearchModuleService.deleteFromIndex(
568 ids,
569 "product"
570 )
571
572 return new StepResponse(undefined, existingRecords)
573 },
574 async (existingRecords, { container }) => {
575 if (!existingRecords) {
576 return
577 }
578 const meilisearchModuleService = container.resolve(MEILISEARCH_MODULE)
579
580 await meilisearchModuleService.indexData(
581 existingRecords,
582 "product"
583 )
584 }
585 )
586 ```
587
588 The step receives the IDs of the products to delete as an input.
589
590 In the step, you resolve the Meilisearch Module's service and retrieve the existing records from Meilisearch. This is useful to revert the deletion if an error occurs.
591
592 Then, you delete the products from Meilisearch and pass the existing records to the compensation function.
593
594 In the compensation function, you reindex the existing records if an error occurs.
595
596 ### Add Sync Products Workflow
597
598 You can now create the workflow that syncs products to Meilisearch.
599
600 To create the workflow, create the file `src/workflows/sync-products.ts` with the following content:
601
602 ```ts title="src/workflows/sync-products.ts"
603 import {
604 createWorkflow,
605 transform,
606 WorkflowResponse,
607 } from "@medusajs/framework/workflows-sdk"
608 import { useQueryGraphStep } from "@medusajs/medusa/core-flows"
609 import { syncProductsStep, SyncProductsStepInput } from "./steps/sync-products"
610 import { deleteProductsFromMeilisearchStep } from "./steps/delete-products-from-meilisearch"
611
612 type SyncProductsWorkflowInput = {
613 filters?: Record<string, unknown>
614 limit?: number
615 offset?: number
616 }
617
618 export const syncProductsWorkflow = createWorkflow(
619 "sync-products",
620 ({ filters, limit, offset }: SyncProductsWorkflowInput) => {
621 const { data: products, metadata } = useQueryGraphStep({
622 entity: "product",
623 fields: [
624 "id",
625 "title",
626 "description",
627 "handle",
628 "thumbnail",
629 "categories.id",
630 "categories.name",
631 "categories.handle",
632 "tags.id",
633 "tags.value",
634 "status",
635 ],
636 pagination: {
637 take: limit,
638 skip: offset,
639 },
640 filters,
641 })
642
643 const {
644 publishedProducts,
645 unpublishedProductsToDelete,
646 } = transform({
647 products,
648 }, (data) => {
649 const publishedProducts: SyncProductsStepInput["products"] = []
650 const unpublishedProductsToDelete: string[] = []
651
652 data.products.forEach((product) => {
653 if (product.status === "published") {
654 const { status, ...rest } = product
655 publishedProducts.push(rest as SyncProductsStepInput["products"][0])
656 } else {
657 unpublishedProductsToDelete.push(product.id)
658 }
659 })
660
661 return {
662 publishedProducts,
663 unpublishedProductsToDelete,
664 }
665 })
666
667 syncProductsStep({
668 products: publishedProducts,
669 })
670
671 deleteProductsFromMeilisearchStep({
672 ids: unpublishedProductsToDelete,
673 })
674
675 return new WorkflowResponse({
676 products,
677 metadata,
678 })
679 }
680 )
681 ```
682
683 You create a workflow using `createWorkflow` from the Workflows SDK. It accepts the workflow's unique name as a first parameter.
684
685 It accepts as a second parameter a constructor function, which is the workflow's implementation. The function can accept input, which in this case is pagination and filter parameters for the products to retrieve.
686
687 In the workflow's constructor function, you:
688
689 1. Retrieve products from Medusa's database using `useQueryGraphStep`. This step uses Medusa's [Query](!docs!/learn/fundamentals/query) tool to retrieve data across modules. You pass it the pagination and filter parameters you received in the input.
690 2. Use [transform](!docs!/learn/fundamentals/workflows/variable-manipulation) to prepare two lists: one for published products to index in Meilisearch and another for unpublished products to delete from Meilisearch.
691 3. Index the published products in Meilisearch using `syncProductsStep`.
692 4. Delete unpublished products from Meilisearch using `deleteProductsFromMeilisearchStep`.
693
694 A workflow must return an instance of `WorkflowResponse`. The `WorkflowResponse` constructor accepts the workflow's output as a parameter, which is an object holding the retrieved products and their pagination details.
695
696 In the next step, you'll learn how to execute this workflow.
697
698 <Note>
699
700 In workflows, you need `transform` to prepare data based on execution values. Learn more in the [Data Manipulation](!docs!/learn/fundamentals/workflows/variable-manipulation) workflow documentation.
701
702 </Note>
703
704 ---
705
706 ## Step 4: Trigger Meilisearch Sync Manually
707
708 As mentioned earlier, you'll trigger the Meilisearch sync automatically when product events occur. You also want to allow admins to manually trigger a reindex.
709
710 In this step, you'll add the functionality to trigger the `syncProductsWorkflow` manually from the Medusa Admin dashboard. This requires:
711
712 1. Creating a subscriber that listens to a custom `meilisearch.sync` event to trigger syncing products to Meilisearch.
713 2. Creating an API route that the Medusa Admin dashboard can call to emit the `meilisearch.sync` event, which triggers the subscriber.
714 3. Adding a new page or UI route to the Medusa Admin dashboard to allow admins to trigger the reindex.
715
716 ### Create Products Sync Subscriber
717
718 A subscriber is an asynchronous function that listens to one or more events and performs actions when these events are emitted. A subscriber is useful when syncing data across systems, as the operation can be time-consuming and should be performed in the background.
719
720 <Note>
721
722 Learn more about subscribers in the [Events and Subscribers documentation](!docs!/learn/fundamentals/events-and-subscribers).
723
724 </Note>
725
726 You create a subscriber in a TypeScript or JavaScript file under the `src/subscribers` directory. So, to create the subscriber that listens to the `meilisearch.sync` event, create the file `src/subscribers/meilisearch-sync.ts` with the following content:
727
728 ```ts title="src/subscribers/meilisearch-sync.ts"
729 import {
730 SubscriberArgs,
731 type SubscriberConfig,
732 } from "@medusajs/framework"
733 import { syncProductsWorkflow } from "../workflows/sync-products"
734 import {
735 ContainerRegistrationKeys,
736 } from "@medusajs/framework/utils"
737
738 export default async function meilisearchSyncHandler({
739 container,
740 }: SubscriberArgs) {
741 const logger = container.resolve(
742 ContainerRegistrationKeys.LOGGER
743 )
744
745 let hasMore = true
746 let offset = 0
747 const limit = 50
748 let totalIndexed = 0
749
750 logger.info("Starting product indexing...")
751
752 while (hasMore) {
753 const { result: { products, metadata } } = await syncProductsWorkflow(container)
754 .run({
755 input: {
756 limit,
757 offset,
758 },
759 })
760
761 hasMore = offset + limit < (metadata?.count ?? 0)
762 offset += limit
763 totalIndexed += products.length
764 }
765
766 logger.info(`Successfully indexed ${totalIndexed} products`)
767 }
768
769 export const config: SubscriberConfig = {
770 event: "meilisearch.sync",
771 }
772 ```
773
774 A subscriber file must export:
775
776 1. An asynchronous function, which is the subscriber that is executed when the event is emitted.
777 2. A configuration object that holds the name of the event the subscriber listens to, which is `meilisearch.sync` in this case.
778
779 The subscriber function receives an object as a parameter that has a `container` property, which is the Medusa container.
780
781 In the subscriber function, you initialize variables to keep track of pagination and the total number of products indexed.
782
783 Then, you start a loop that retrieves products in batches of 50. It indexes them in Meilisearch using the `syncProductsWorkflow`. Finally, you log the total number of products indexed.
784
785 You'll learn how to emit the `meilisearch.sync` event next.
786
787 <Note title="Tip">
788
789 If you want to sync other data types, you can do it in this subscriber as well.
790
791 </Note>
792
793 ### Create API Route to Trigger Sync
794
795 To allow the Medusa Admin dashboard to trigger the `meilisearch.sync` event, you need to create an API route that emits the event.
796
797 An API Route is an endpoint that exposes commerce features to external applications and clients, such as storefronts.
798
799 <Note>
800
801 Learn more about API routes in [this documentation](!docs!/learn/fundamentals/api-routes).
802
803 </Note>
804
805 An API route is created in a `route.ts` file under a subdirectory of the `src/api` directory. The path of the API route is the file's path relative to `src/api`.
806
807 So, to create an API route at the path `/admin/meilisearch/sync`, create the file `src/api/admin/meilisearch/sync/route.ts` with the following content:
808
809 ```ts title="src/api/admin/meilisearch/sync/route.ts"
810 import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"
811 import { Modules } from "@medusajs/framework/utils"
812
813 export async function POST(
814 req: MedusaRequest,
815 res: MedusaResponse
816 ) {
817 const eventModuleService = req.scope.resolve(Modules.EVENT_BUS)
818 await eventModuleService.emit({
819 name: "meilisearch.sync",
820 data: {},
821 })
822 res.send({
823 message: "Syncing data to Meilisearch",
824 })
825 }
826
827 ```
828
829 Since you export a `POST` route handler function, you expose a `POST` API route at `/admin/meilisearch/sync`. The route handler function accepts two parameters:
830
831 1. A request object with details and context on the request, such as body parameters or authenticated user details.
832 2. A response object to manipulate and send the response.
833
834 In the route handler, you use the Medusa container that is available in the request object. You resolve the [Event Module](../../../infrastructure-modules/event/page.mdx). This module manages events and their subscribers.
835
836 Then, you emit the `meilisearch.sync` event using the Event Module's `emit` method. You pass it the event name.
837
838 Finally, you send a response with a message indicating that data is being synced to Meilisearch.
839
840 ### Add Meilisearch Sync Page to Admin Dashboard
841
842 The last step is to add a new page to the admin dashboard. This page allows admins to trigger the reindex. You add a new page using a [UI Route](!docs!/learn/fundamentals/admin/ui-routes).
843
844 A UI route is a React component that specifies the content to be shown in a new page in the Medusa Admin dashboard. You'll create a UI route to display a button that triggers the reindex when clicked.
845
846 <Note>
847
848 Learn more about UI routes in the [UI Routes documentation](!docs!/learn/fundamentals/admin/ui-routes).
849
850 </Note>
851
852 #### Configure JS SDK
853
854 Before creating the UI route, you'll configure Medusa's [JS SDK](../../../js-sdk/page.mdx). You can use it to send requests to the Medusa server from any client application, including your Medusa Admin customizations.
855
856 The JS SDK is installed by default in your Medusa application. To configure it, create the file `src/admin/lib/sdk.ts` with the following content:
857
858 ```ts title="src/admin/lib/sdk.ts"
859 import Medusa from "@medusajs/js-sdk"
860
861 export const sdk = new Medusa({
862 baseUrl: import.meta.env.VITE_BACKEND_URL || "/",
863 debug: import.meta.env.DEV,
864 auth: {
865 type: "session",
866 },
867 })
868 ```
869
870 You create an instance of the JS SDK using the `Medusa` class from the JS SDK. You pass it an object having the following properties:
871
872 - `baseUrl`: The base URL of the Medusa server.
873 - `debug`: A boolean indicating whether to log debug information into the console.
874 - `auth`: An object specifying the authentication type. When using the JS SDK for admin customizations, you use the `session` authentication type.
875
876 #### Create UI Route
877
878 You'll now create the UI route that displays a button to trigger the reindex. You create a UI route in a `page.tsx` file under a subdirectory of `src/admin/routes` directory. The file's path relative to `src/admin/routes` determines its path in the dashboard.
879
880 So, to create a new page under the Settings section of the Medusa Admin, create the file `src/admin/routes/settings/meilisearch/page.tsx` with the following content:
881
882 ```tsx title="src/admin/routes/settings/meilisearch/page.tsx"
883 import { Container, Heading, Button, toast } from "@medusajs/ui"
884 import { useMutation } from "@tanstack/react-query"
885 import { sdk } from "../../../lib/sdk"
886 import { defineRouteConfig } from "@medusajs/admin-sdk"
887
888 const MeilisearchPage = () => {
889 const { mutate, isPending } = useMutation({
890 mutationFn: () =>
891 sdk.client.fetch("/admin/meilisearch/sync", {
892 method: "POST",
893 }),
894 onSuccess: () => {
895 toast.success("Successfully triggered data sync to Meilisearch")
896 },
897 onError: (err) => {
898 console.error(err)
899 toast.error("Failed to sync data to Meilisearch")
900 },
901 })
902
903 const handleSync = () => {
904 mutate()
905 }
906
907 return (
908 <Container className="divide-y p-0">
909 <div className="flex items-center justify-between px-6 py-4">
910 <Heading level="h2">Meilisearch Sync</Heading>
911 </div>
912 <div className="px-6 py-8">
913 <Button
914 variant="primary"
915 onClick={handleSync}
916 isLoading={isPending}
917 >
918 Sync Data to Meilisearch
919 </Button>
920 </div>
921 </Container>
922 )
923 }
924
925 export const config = defineRouteConfig({
926 label: "Meilisearch",
927 })
928
929 export default MeilisearchPage
930 ```
931
932 A UI route's file must export:
933
934 1. A React component that defines the content of the page.
935 2. A configuration object that specifies the route's label in the dashboard. This label is used to show a sidebar item for the new route.
936
937 In the React component, you use `useMutation` hook from `@tanstack/react-query` to create a mutation that sends a `POST` request to the API route you created earlier. In the mutation function, you use the JS SDK to send the request.
938
939 Then, in the return statement, you display a button that triggers the mutation when clicked, which sends a request to the API route you created earlier.
940
941 ### Test it Out
942
943 You'll now test out the entire flow. Start by triggering the reindex manually from the Medusa Admin dashboard, then check the Meilisearch dashboard for the indexed products.
944
945 Run the following command to start the Medusa application:
946
947 ```bash npm2yarn
948 npm run dev
949 ```
950
951 Then, open the Medusa Admin at `http://localhost:9000/app` and log in with the credentials you set up in the first step.
952
953 <Note>
954
955 Can't remember the credentials? Learn how to create a user in the [Medusa CLI reference](../../../medusa-cli/commands/user/page.mdx).
956
957 </Note>
958
959 After you log in, go to Settings from the sidebar. You'll find a new "Meilisearch" item in the Settings' sidebar. If you click on it, you'll find the page you created with the button to sync products to Meilisearch.
960
961 If you click on the button, the products will be synced to Meilisearch.
962
963 ![The Meilisearch Sync page in the Medusa Admin dashboard with a button to sync products to Meilisearch](https://res.cloudinary.com/dza7lstvk/image/upload/v1758094934/Medusa%20Resources/CleanShot_2025-09-17_at_10.41.51_2x_wph4pp.png)
964
965 You can check that the sync ran and was completed by checking the Medusa logs in the terminal where you started the Medusa application. You should find the following messages:
966
967 ```bash
968 info: Processing meilisearch.sync which has 1 subscribers
969 info: Starting product indexing...
970 info: Successfully indexed 4 products
971 ```
972
973 These messages indicate that the `meilisearch.sync` event was emitted, which triggered the subscriber you created to sync the products using the `syncProductsWorkflow`.
974
975 Finally, you can check the Meilisearch dashboard to see the indexed products. Open the Meilisearch dashboard, either Cloud or local, and choose the index you specified for products in the environment variable `MEILISEARCH_PRODUCT_INDEX_NAME`. You'll find your Medusa products indexed there.
976
977 ![The Meilisearch dashboard showing the indexed products](https://res.cloudinary.com/dza7lstvk/image/upload/v1758095145/Medusa%20Resources/CleanShot_2025-09-17_at_10.45.29_2x_y8ytzf.png)
978
979 ---
980
981 ## Step 5: Update Index on Product Changes
982
983 You'll now automate the indexing of products whenever a change occurs. This includes when a product is created, updated, or deleted.
984
985 Similar to before, you'll create subscribers to listen to these events.
986
987 ### Handle Create and Update Products
988
989 The action to perform when a product is created or updated is the same. You'll use the `syncProductsWorkflow` to sync the product to Meilisearch.
990
991 So, you only need one subscriber to handle these two events. To create the subscriber, create the file `src/subscribers/product-sync.ts` with the following content:
992
993 ```ts title="src/subscribers/product-sync.ts"
994 import {
995 SubscriberArgs,
996 type SubscriberConfig,
997 } from "@medusajs/framework"
998 import { syncProductsWorkflow } from "../workflows/sync-products"
999
1000 export default async function handleProductEvents({
1001 event: { data },
1002 container,
1003 }: SubscriberArgs<{ id: string }>) {
1004 await syncProductsWorkflow(container)
1005 .run({
1006 input: {
1007 filters: {
1008 id: data.id,
1009 },
1010 },
1011 })
1012 }
1013
1014 export const config: SubscriberConfig = {
1015 event: ["product.created", "product.updated"],
1016 }
1017 ```
1018
1019 The subscriber listens to the `product.created` and `product.updated` events. When either of these events is emitted, the subscriber triggers the `syncProductsWorkflow` to sync the product to Meilisearch.
1020
1021 When the `product.created` and `product.updated` events are emitted, the product's ID is passed in the event data payload. You can access this in the `event.data` property of the subscriber function's parameter.
1022
1023 So, you pass the product's ID to the `syncProductsWorkflow` as a filter to retrieve only the product that was created or updated.
1024
1025 #### Test it Out
1026
1027 To test it out, start the Medusa application:
1028
1029 ```bash npm2yarn
1030 npm run dev
1031 ```
1032
1033 Then, either create a product or update an existing one using the Medusa Admin dashboard. If you check the Meilisearch dashboard, you'll find that the product's index was created or updated.
1034
1035 ### Handle Product Deletion
1036
1037 When a product is deleted, you need to remove it from the Meilisearch index. This requires a different action than creating or updating a product.
1038
1039 You'll create a new workflow that deletes the product from Meilisearch, then create a subscriber that listens to the `product.deleted` event to trigger the workflow.
1040
1041 #### Create Delete Product Workflow
1042
1043 Since you've already implemented the `deleteProductsFromMeilisearchStep`, you can create the workflow that uses this step.
1044
1045 Create the file `src/workflows/delete-products-from-meilisearch.ts` with the following content:
1046
1047 ```ts title="src/workflows/delete-products-from-meilisearch.ts"
1048 import { createWorkflow } from "@medusajs/framework/workflows-sdk"
1049 import { deleteProductsFromMeilisearchStep } from "./steps/delete-products-from-meilisearch"
1050
1051 type DeleteProductsFromMeilisearchWorkflowInput = {
1052 ids: string[]
1053 }
1054
1055 export const deleteProductsFromMeilisearchWorkflow = createWorkflow(
1056 "delete-products-from-meilisearch",
1057 (input: DeleteProductsFromMeilisearchWorkflowInput) => {
1058 deleteProductsFromMeilisearchStep(input)
1059 }
1060 )
1061 ```
1062
1063 The workflow receives an object with the IDs of the products to delete. It then executes the `deleteProductsFromMeilisearchStep` to delete the products from Meilisearch.
1064
1065 #### Create Delete Product Subscriber
1066
1067 Next, you'll create the subscriber that listens to the `product.deleted` event to trigger the above workflow.
1068
1069 Create the file `src/subscribers/product-delete.ts` with the following content:
1070
1071 ```ts title="src/subscribers/product-delete.ts"
1072 import {
1073 SubscriberArgs,
1074 type SubscriberConfig,
1075 } from "@medusajs/framework"
1076 import { deleteProductsFromMeilisearchWorkflow } from "../workflows/delete-products-from-meilisearch"
1077 import {
1078 ContainerRegistrationKeys,
1079 } from "@medusajs/framework/utils"
1080
1081 export default async function productDeleteHandler({
1082 event: { data },
1083 container,
1084 }: SubscriberArgs<{ id: string }>) {
1085 const logger = container.resolve(
1086 ContainerRegistrationKeys.LOGGER
1087 )
1088
1089 logger.info(`Deleting product ${data.id} from Meilisearch`)
1090
1091 await deleteProductsFromMeilisearchWorkflow(container)
1092 .run({
1093 input: {
1094 ids: [data.id],
1095 },
1096 })
1097 }
1098
1099 export const config: SubscriberConfig = {
1100 event: "product.deleted",
1101 }
1102 ```
1103
1104 The subscriber listens to the `product.deleted` event. When the event is emitted, the subscriber triggers the `deleteProductsFromMeilisearchWorkflow`, passing it the ID of the product to delete.
1105
1106 #### Test it Out
1107
1108 To test product deletion, start the Medusa application:
1109
1110 ```bash npm2yarn
1111 npm run dev
1112 ```
1113
1114 Then, delete a product from the Medusa Admin dashboard. If you check the Meilisearch dashboard, you'll find that the product index was deleted there as well.
1115
1116 ---
1117
1118 ## Step 6: Search Products in Next.js Starter Storefront
1119
1120 The last step is to provide search functionalities to customers on your storefront. In the first step, you installed the [Next.js Starter Storefront](../../../nextjs-starter/page.mdx) along with the Medusa application.
1121
1122 In this step, you'll customize the Next.js Starter Storefront to add search functionality.
1123
1124 <Note title="Reminder" forceMultiline>
1125
1126 The Next.js Starter Storefront is available in the `apps/storefront` directory of your project:
1127
1128 ```bash
1129 cd apps/storefront
1130 ```
1131
1132 </Note>
1133
1134 ### Install Meilisearch Packages
1135
1136 Before adding the implementation of search functionality, you need to install the Meilisearch packages necessary to add search functionality in your storefront.
1137
1138 Run the following command in the directory of your Next.js Starter Storefront:
1139
1140 ```bash npm2yarn
1141 npm install @meilisearch/instant-meilisearch react-instantsearch
1142 ```
1143
1144 This installs the Meilisearch InstantSearch JavaScript library and the React InstantSearch library. You'll use these to build the search functionality.
1145
1146 ### Add Search Client Configuration
1147
1148 Next, you need to configure the Meilisearch search client.
1149
1150 In `src/lib/config.ts`, add the following imports at the top of the file:
1151
1152 ```ts title="src/lib/config.ts" badgeLabel="Storefront" badgeColor="blue"
1153 import {
1154 instantMeiliSearch,
1155 } from "@meilisearch/instant-meilisearch"
1156 ```
1157
1158 Then, add the following at the end of the file:
1159
1160 ```ts title="src/lib/config.ts" badgeLabel="Storefront" badgeColor="blue"
1161 export const { searchClient } = instantMeiliSearch(
1162 process.env.NEXT_PUBLIC_MEILISEARCH_HOST || "",
1163 process.env.NEXT_PUBLIC_MEILISEARCH_API_KEY || ""
1164 )
1165 ```
1166
1167 In the code above, you create a `searchClient` object that initializes the Meilisearch client with your Meilisearch host and API Key.
1168
1169 ### Set Environment Variables
1170
1171 In the storefront's `.env.local` file, add the following Meilisearch-related environment variables:
1172
1173 ```plain badgeLabel="Storefront" badgeColor="blue"
1174 NEXT_PUBLIC_MEILISEARCH_HOST=your_meilisearch_host
1175 NEXT_PUBLIC_MEILISEARCH_API_KEY=your_meilisearch_api_key
1176 NEXT_PUBLIC_MEILISEARCH_INDEX_NAME=your-products-index-name
1177 ```
1178
1179 Where:
1180
1181 - `your_meilisearch_host` is your Meilisearch host, as explained in the [Add Environment Variables section](#add-environment-variables) earlier.
1182 - `your_meilisearch_api_key` is your Meilisearch API key with search permissions. You can retrieve it as explained in the [Meilisearch Documentation](https://www.meilisearch.com/docs/learn/security/basic_security#obtaining-api-keys).
1183 - `your-products-index-name` is the name of the index you created in Meilisearch to store the products. You can retrieve this as explained in the [Add Environment Variables section](#add-environment-variables) earlier. You'll use this variable later.
1184
1185 <Note type="warning">
1186
1187 Do not use the `masterKey` as the API key in the storefront, as it has all permissions, including write permissions. Only use an API key with search permissions.
1188
1189 </Note>
1190
1191 ### Add Search Modal Component
1192
1193 You'll now add a search modal component that customers can use to search for products. The search modal will display search results in real-time as the customer types in the search query.
1194
1195 Later, you'll add the search modal to the navigation bar. This allows customers to open the search modal from any page.
1196
1197 Create the file `src/modules/search/components/modal/index.tsx` with the following content:
1198
1199 ```tsx title="src/modules/search/components/modal/index.tsx" badgeLabel="Storefront" badgeColor="blue"
1200 "use client"
1201
1202 import React, { useEffect, useState } from "react"
1203 import { Hits, InstantSearch, SearchBox } from "react-instantsearch"
1204 import { searchClient } from "../../../../lib/config"
1205 import Modal from "../../../common/components/modal"
1206 import { Button } from "@medusajs/ui"
1207 import Image from "next/image"
1208 import Link from "next/link"
1209 import { usePathname } from "next/navigation"
1210
1211 type Hit = {
1212 id: string;
1213 title: string;
1214 description: string;
1215 handle: string;
1216 thumbnail: string;
1217 categories: {
1218 id: string
1219 name: string
1220 handle: string
1221 }[]
1222 tags: {
1223 id: string
1224 value: string
1225 }[]
1226 }
1227
1228 export default function SearchModal() {
1229 const [isOpen, setIsOpen] = useState(false)
1230 const pathname = usePathname()
1231
1232 useEffect(() => {
1233 setIsOpen(false)
1234 }, [pathname])
1235
1236 return (
1237 <>
1238 <div className="hidden small:flex items-center gap-x-6 h-full">
1239 <Button
1240 onClick={() => setIsOpen(true)}
1241 variant="transparent"
1242 className="hover:text-ui-fg-base text-small-regular px-0 hover:bg-transparent focus:!bg-transparent"
1243 >
1244 Search
1245 </Button>
1246 </div>
1247 <Modal isOpen={isOpen} close={() => setIsOpen(false)}>
1248 <InstantSearch
1249 // @ts-expect-error - searchClient type issue
1250 searchClient={searchClient}
1251 indexName={process.env.NEXT_PUBLIC_MEILISEARCH_INDEX_NAME}
1252 >
1253 <SearchBox className="w-full [&_input]:w-[94%] [&_input]:outline-none [&_button]:w-[3%]" />
1254 <Hits hitComponent={Hit} />
1255 </InstantSearch>
1256 </Modal>
1257 </>
1258 )
1259 }
1260
1261 const Hit = ({ hit }: { hit: Hit }) => {
1262 return (
1263 <div className="flex flex-row gap-x-2 mt-4 relative" key={hit.id}>
1264 <Image src={hit.thumbnail} alt={hit.title} width={100} height={100} />
1265 <div className="flex flex-col gap-y-1">
1266 <h3>{hit.title}</h3>
1267 <p className="text-sm text-gray-500">{hit.description}</p>
1268 </div>
1269 <Link href={`/products/${hit.handle}`} className="absolute right-0 top-0 w-full h-full" aria-label={`View Product: ${hit.title}`} />
1270 </div>
1271 )
1272 }
1273 ```
1274
1275 You create a `SearchModal` component that displays a search box and search results using widgets from the `react-instantsearch` library.
1276
1277 To display each result item (or hit), you create a `Hit` component. This component displays the product's title, description, and thumbnail. You also add a link to the product's page.
1278
1279 Finally, you show the search modal when the customer clicks a "Search" button. You'll add this button to the navigation bar next.
1280
1281 ### Add Search Button to Navigation Bar
1282
1283 The last step is to show the search button in the navigation bar.
1284
1285 In `src/modules/layout/templates/nav/index.tsx`, add the following imports at the top of the file:
1286
1287 ```tsx title="src/modules/layout/templates/nav/index.tsx" badgeLabel="Storefront" badgeColor="blue"
1288 import SearchModal from "@modules/search/components/modal"
1289 ```
1290
1291 Then, in the return statement of the `Nav` component, add the `SearchModal` component before the `div` surrounding the "Account" link:
1292
1293 ```tsx title="src/modules/layout/templates/nav/index.tsx" badgeLabel="Storefront" badgeColor="blue"
1294 <SearchModal />
1295 ```
1296
1297 The search button will now appear in the navigation bar before the Account link.
1298
1299 ### Test it Out
1300
1301 To test out the storefront changes and the search API route, start the Medusa application:
1302
1303 ```bash npm2yarn
1304 npm run dev
1305 ```
1306
1307 Then, start the Next.js Starter Storefront from its directory:
1308
1309 ```bash npm2yarn
1310 npm run dev
1311 ```
1312
1313 Next, go to `localhost:8000`. You'll find a Search button at the top right of the navigation bar. If you click on it, you can search through your products. You can also click on a product to view its page.
1314
1315 ![The Next.js Starter Storefront showing the search modal with search results](https://res.cloudinary.com/dza7lstvk/image/upload/v1758096281/Medusa%20Resources/CleanShot_2025-09-17_at_11.04.26_2x_bhb9k7.png)
1316
1317 ---
1318
1319 ## Next Steps
1320
1321 You've now integrated Meilisearch with Medusa and added search functionality to your storefront. You can expand on these features to:
1322
1323 - Add filters to the search results. You can do that using [react-instantsearch widgets](https://www.algolia.com/doc/guides/building-search-ui/widgets/showcase/react/).
1324 - Support indexing other data types, such as product categories. You can create subscribers and workflows for categories similar to products.
1325
1326 ### Learn More about Medusa
1327
1328 If you're new to Medusa, check out the [main documentation](!docs!/learn), where you'll get a more in-depth understanding of all the concepts you've used in this guide and more.
1329
1330 To learn more about the commerce features that Medusa provides, check out Medusa's [Commerce Modules](../../../commerce-modules/page.mdx).
1331
1332 ### Troubleshooting
1333
1334 If you encounter issues during your development, check out the [troubleshooting guides](../../../troubleshooting/page.mdx).
1335
1336 ### Getting Help
1337
1338 If you encounter issues not covered in the troubleshooting guides:
1339
1340 1. Visit the [Medusa GitHub repository](https://github.com/medusajs/medusa) to report issues or ask questions.
1341 2. Join the [Medusa Discord community](https://discord.gg/medusajs) for real-time support from community members.