You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: www/apps/docs/content/plugins/search/meilisearch.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ In this document, you’ll learn how to install the [MeiliSearch plugin](https:/
13
13
14
14
MeiliSearch also provides a pleasant developer experience, as it is extremely intuitive and newcomer-friendly. So, even if you're new to the search engine ecosystem, [their documentation](https://docs.meilisearch.com/) is resourceful enough for everyone to go through and understand.
15
15
16
-
Through Medusa's flexible plugin system, it is possible to add a search engine to your Medusa backend and storefront using MeiliSearch with just a few steps.
16
+
Through Medusa's flexible plugin system, it's possible to add a search engine to your Medusa backend and storefront using MeiliSearch with just a few steps.
17
17
18
18
---
19
19
@@ -27,7 +27,7 @@ It is required to have a Medusa backend installed before starting with this docu
27
27
28
28
You must install MeiliSearch to use it with Medusa. You can follow [this documentation to install MeiliSearch](https://docs.meilisearch.com/learn/getting_started/quick_start.html#setup-and-installation) either locally or on a cloud.
29
29
30
-
Furthermore, you should create a master key for your MeiliSearch instance. If you don’t have one created, follow [this guide](https://docs.meilisearch.com/learn/security/master_api_keys.html#protecting-a-meilisearch-instance) to create a master key.
30
+
Furthermore, you should create a master key for your MeiliSearch instance. If you don’t have one created, follow [this guide](https://www.meilisearch.com/docs/learn/security/master_api_keys#protecting-a-meilisearch-instance) to create a master key.
Where`<YOUR_MEILISEARCH_HOST>` is the host of your MeiliSearch instance. By default, if MeiliSearch is installed locally, the host is `http://127.0.0.1:7700`.
49
+
Where:
50
50
51
-
`<YOUR_MASTER_KEY>` is the master key of your MeiliSearch instance.
51
+
-`<YOUR_MEILISEARCH_HOST>` is the host of your MeiliSearch instance. By default, if MeiliSearch is installed locally, the host is `http://127.0.0.1:7700`.
52
+
-`<YOUR_MASTER_KEY>` is the master key of your MeiliSearch instance.
52
53
53
54
Finally, in `medusa-config.js` add the following item into the `plugins` array:
@@ -141,60 +141,31 @@ Your Next.js Starter Storefront is now running at `localhost:8000`
141
141
142
142
---
143
143
144
-
## Development Notes
145
-
146
-
### Changing Medusa Backend URL
147
-
148
-
By default, the Medusa backend runs at `http://localhost:9000`. This value is defined in your Next.js starter Storefront under the environment variable `NEXT_PUBLIC_MEDUSA_BACKEND_URL`.
149
-
150
-
If you need to change the URL of your Medusa backend because you changed the backend's default port or because you deployed your backend, change the value of `NEXT_PUBLIC_MEDUSA_BACKEND_URL` (typically in `.env.local`) to your backend URL. For example:
The Product Module is currently in beta. You can learn more about it [here](../experimental/product/install-nodejs.md). In addition, the product module in the Next.js storefront can't be used without the Medusa backend at the moment.
161
-
162
-
:::
144
+
## Storefront Features
163
145
164
-
This starter has full support for the serverless Product Module for retrieving and manipulating product data directly from a serverless function. This keeps your product logic close to the frontend, making it easy to customize or extend Medusa's core functionality from within your Next.js project.
146
+
### Featured products on homepage
165
147
166
-
By default, this starter uses the standard Medusa API for product and collection retrieval.
148
+
Your store's products are showcased on the homepage. If you don't see any products, make sure to [create collections and add products to them](../user-guide/products/collections.mdx).
167
149
168
-
To enable the Product Module, first, make sure to set the following environment variables:
150
+

169
151
170
-
-`PRODUCT_POSTGRES_URL`: the URL of your PostgreSQL databsae.
171
-
-`NEXT_PUBLIC_BASE_URL`: the URL of your storefront's base URL. For exmaple, if you're running it locally, it should be `http://localhost:8000`.
152
+
### View all products and manage your cart
172
153
173
-
Then, enable the `productModule` feature flag in `store.config.json`:
If you go to `localhost:8000`, all product and collection data should now be coming from the module. The Product Module routes are all in the `src/app/api` directory for you to customize to your use case.
To opt out of using the product module, simply set the `productModule` feature flag in `store.config.json` to `false` and restart the server.
164
+
---
194
165
195
-
###Toggle Search Engine Feature
166
+
## Toggle Search Engine Feature
196
167
197
-
The Next.js Starter Storefront by default is compatible with MeiliSearch.
168
+
The Next.js Starter Storefront by default is compatible with the MeiliSearch plugin.
198
169
199
170
To enable or disable the search engine, change the value of the feature in `store.config.json`:
200
171
@@ -206,25 +177,25 @@ To enable or disable the search engine, change the value of the feature in `stor
206
177
}
207
178
```
208
179
209
-
Then, restart your Next.js backend. Depending on whether you enabled or disabled the search engine, the search bar will appear or disappear in the navigation bar accordingly.
180
+
Then, restart your Next.js backend. Depending on whether you enabled or disabled the search engine, the "Search" link in the navigation bar will appear or disappear accordingly.
210
181
211
182
### MeiliSearch Integration
212
183
213
-
If you have the search engine feature enabled, it is expected that you have installed the MeiliSearch plugin on your Medusa backend. If not, [follow this guide to install it](../plugins/search/meilisearch.md).
184
+
If you have the search engine feature enabled, it's expected that you have installed the MeiliSearch plugin on your Medusa backend. If not, [follow this guide to install it](../plugins/search/meilisearch.md).
214
185
215
186
In your Next.js Starter Storefront, set the environment variables necessary for the MeiliSearch integration:
`<YOUR_MEILISEARCH_URL>` is the URL MeiliSearch is running on. The default is `http://127.0.0.1:7700`.
224
-
225
-
`NEXT_PUBLIC_INDEX_NAME` is the index name of the products in MeiliSearch. By default, it’s `products`.
194
+
Where:
226
195
227
-
`<YOUR_API_KEY>` is the API key used to search through MeiliSearch indexes. To create a new API Key, make sure that the MeiliSearch service is running and send the following request:
196
+
-`<YOUR_MEILISEARCH_URL>` is the URL MeiliSearch is running on. The default is `http://127.0.0.1:7700`.
197
+
-`NEXT_PUBLIC_INDEX_NAME` is the index name of the products in MeiliSearch. By default, it’s `products`.
198
+
-`<YOUR_API_KEY>` is the API key used to search through MeiliSearch indexes. To create a new API Key, make sure that the MeiliSearch service is running and send the following request:
228
199
229
200
```bash
230
201
curl \
@@ -239,33 +210,40 @@ curl \
239
210
}'
240
211
```
241
212
242
-
Make sure to replace `<MEILISEARCH_URL>` with the URL MeiliSearch is running on and `<MEILISEARCH_MASTER_KEY>` with your MeiliSearch [master key](https://docs.meilisearch.com/learn/security/master_api_keys.html#protecting-a-meilisearch-instance).
213
+
Make sure to replace `<MEILISEARCH_URL>` with the URL MeiliSearch is running on and `<MEILISEARCH_MASTER_KEY>` with your MeiliSearch [master key](https://www.meilisearch.com/docs/learn/security/master_api_keys#protecting-a-meilisearch-instance).
243
214
244
-
Then, restart the Next.js backend. You’ll be able to search through available products by clicking the search icon in the navigation bar.
215
+
Then, restart the Next.js storefront. You’ll be able to search through available products by clicking the search icon in the navigation bar.
245
216
246
-
:::note
217
+
:::tip
247
218
248
-
To make sure the Next.js Starter Storefront properly displays the products in the search result, include in the `displayedAttributes` setting of the MeiliSearch plugin on the Medusa backend at least the fields `title`, `handle`, `description`, and `thumbnail`.
219
+
To make sure the Next.js Storefront properly displays the products in the search result, include in the `displayedAttributes` setting of the MeiliSearch plugin on the Medusa backend at least the fields `title`, `handle`, `description`, and `thumbnail`.
249
220
250
221
:::
251
222
252
-

223
+

253
224
254
225
### Algolia Integration
255
226
256
227
Instead of using the default MeiliSearch search engine, you can switch to using Algolia. Make sure you start by installing the Algolia plugin on your Medusa backend. You can do it by [following this guide](../plugins/search/algolia.md).
257
228
258
-
In your Next.js Starter Storefront, set the environment variables necessary for the Algolia integration:
229
+
In your Next.js Starter Storefront, install the `algoliasearch` package in your Next.js storefront:
230
+
231
+
```bash npm2yarn
232
+
npm install algoliasearch
233
+
```
234
+
235
+
Then, set the environment variables necessary for the Algolia integration:
259
236
260
237
```bash
261
238
NEXT_PUBLIC_SEARCH_APP_ID=<YOUR_APP_ID>
262
239
NEXT_PUBLIC_SEARCH_API_KEY=<YOUR_SEARCH_API_KEY>
263
240
NEXT_PUBLIC_INDEX_NAME=products
264
241
```
265
242
266
-
Where`<YOUR_APP_ID>` and `<YOUR_SEARCH_API_KEY>` are the Algolia App ID and Algolia Search API Key respectively. You can retrieve them from Algolia by going to [API Keys](https://www.algolia.com/account/api-keys/all) in your account settings.
243
+
Where:
267
244
268
-
`NEXT_PUBLIC_INDEX_NAME` is the index name of the products in Algolia. By default, it’s `products`.
245
+
-`<YOUR_APP_ID>` and `<YOUR_SEARCH_API_KEY>` are the Algolia App ID and Algolia Search API Key respectively. You can retrieve them from Algolia by going to [API Keys](https://www.algolia.com/account/api-keys/all) in your account settings.
246
+
-`NEXT_PUBLIC_INDEX_NAME` is the index name of the products in Algolia. By default, it’s `products`.
269
247
270
248
Next, change the content of `src/lib/search-client.ts` to the following:
Then, restart the Next.js backend. You’ll be able to search through available products by clicking the search icon in the navigation bar.
263
+
Next, change the content of `src/app/(main)/search/actions.ts` to the following:
264
+
265
+
```ts title="src/app/(main)/search/actions.ts"
266
+
"use server"
267
+
268
+
import {
269
+
searchClient,
270
+
SEARCH_INDEX_NAME,
271
+
} from"@lib/search-client"
272
+
273
+
/**
274
+
* Uses MeiliSearch or Algolia to search for a query
275
+
* @param{string}query - search query
276
+
*/
277
+
exportasyncfunction search(query:string) {
278
+
const index =searchClient.initIndex(SEARCH_INDEX_NAME)
279
+
const { hits } =awaitindex.search(query)
280
+
281
+
returnhits
282
+
}
283
+
```
286
284
287
-

285
+
Finally, restart the Next.js backend. You’ll be able to search through available products by clicking the search icon in the navigation bar.
286
+
287
+

288
+
289
+
---
290
+
291
+
## Payment Integrations
288
292
289
293
### Stripe Payment Integration
290
294
@@ -300,8 +304,6 @@ Make sure to replace `<YOUR_PUBLISHABLE_KEY>` with your Stripe publishable key.
300
304
301
305
If you restart your Next.js backend you should be able to pay with Stripe on checkout.
302
306
303
-

304
-
305
307
### PayPal Payment Integration
306
308
307
309
PayPal integration is supported by default. Make sure you have PayPal installed and enabled on your Medusa backend first. You can [follow this guide to learn how to install it](../plugins/payment/paypal.md).
@@ -316,15 +318,19 @@ Make sure to replace `<YOUR_CLIENT_ID>` with your PayPal client ID. You can retr
316
318
317
319
If you restart your Next.js backend you should be able to pay with PayPal on checkout.
318
320
319
-

321
+
---
320
322
321
-
### Customization
323
+
##Development Notes
322
324
323
-
To customize the pages of the storefront, you can customize the files under the `src/pages` directory.
325
+
### Changing Medusa Backend URL
324
326
325
-
To customize the components used in the storefront, you can customize the files under the `src/modules` directory.
327
+
By default, the Medusa backend runs at `http://localhost:9000`. This value is defined in your Next.js starter Storefront under the environment variable `NEXT_PUBLIC_MEDUSA_BACKEND_URL`.
326
328
327
-
To customize the styles of the storefront, you can customize the `src/styles` directory.
329
+
If you need to change the URL of your Medusa backend because you changed the backend's default port or because you deployed your backend, change the value of `NEXT_PUBLIC_MEDUSA_BACKEND_URL` (typically in `.env.local`) to your backend URL. For example:
@@ -347,25 +353,67 @@ Then, on your backend, update the environment variable `STORE_CORS` to the URL w
347
353
STORE_CORS=http://localhost:<PORT>
348
354
```
349
355
350
-
### Development Resources
356
+
### Using Serverless Modules
351
357
352
-
You can learn more about development with Next.js through [their documentation](https://nextjs.org/docs/getting-started).
358
+
:::note
353
359
354
-
---
360
+
Serverless Modules are currently in beta and, at the moment, they can't be used in the Next.js storefront without the Medusa backend running.
355
361
356
-
## Storefront Features
362
+
:::
357
363
358
-
- View all products and manage your cart.
364
+
This starter fully supports the experimental [Product](../experimental/product/overview.mdx)and [Pricing](../experimental/pricing/overview.mdx) modules for retrieving and manipulating product and pricing data directly from a serverless function. This keeps your logic close to the frontend, making it easy to customize or extend Medusa's core functionality from within your Next.js project.
By default, this starter uses the standard Medusa API for product, collection, and pricing retrieval.
367
+
368
+
To enable the usage of the experimental modules, first, set the following environment variables:
369
+
370
+
-`POSTGRES_URL`: the URL of your PostgreSQL databsae.
371
+
-`NEXT_PUBLIC_BASE_URL`: the URL of your storefront's base URL. For exmaple, if you're running it locally, it should be `http://localhost:8000`.
361
372
362
-
- Customer authentication and profiles.
373
+
Then, set the following environment variable in both the Next.js storefront and the [Medusa backend](../experimental/index.md#enabling-experimental-features):
You can now test it out now. Make sure the Medusa backend is running, then start (or restart) your Next.js storefront:
393
+
394
+
```bash npm2yarn
395
+
npm run start
396
+
```
397
+
398
+
If you go to `localhost:8000`, all product and collection data should now be coming from the module. The Product Module routes are all in the `src/app/api` directory for you to customize to your use case.
399
+
400
+
:::info[Deploying to Vercel]
401
+
402
+
If you're not planning on using the serverless modules, you might encounter errors when deploying to Vercel. You can safely delete or exclude `the src/app/api` folder before deploying. The API routes are only used by the serverless modules.
403
+
404
+
:::
405
+
406
+
### Customization
407
+
408
+
To customize the pages of the storefront, you can customize the files under the `src/app` directory.
409
+
410
+
To customize the components used in the storefront, you can customize the files under the `src/modules` directory.
411
+
412
+
To customize the styles of the storefront, you can customize the `src/styles` directory.
413
+
414
+
### Development Resources
415
+
416
+
You can learn more about development with Next.js through [their documentation](https://nextjs.org/docs/getting-started).
0 commit comments