Skip to content

Commit 7f2221e

Browse files
Add support for indexing with wildcard locale
1 parent 2add7d0 commit 7f2221e

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ You will need both a running Strapi app and a running Meilisearch instance. For
7676

7777
⚡️ **Launch, scale, and streamline in minutes with Meilisearch Cloud**—no maintenance, no commitment, cancel anytime. [Try it free now](https://cloud.meilisearch.com/login?utm_campaign=oss&utm_source=github&utm_medium=strapi-plugin-meilisearch).
7878

79-
🪨 Prefer to self-host? [Download and deploy](https://www.meilisearch.com/docs/learn/self_hosted/getting_started_with_self_hosted_meilisearch?utm_campaign=oss&utm_source=github&utm_medium=strapi-plugin-meilisearch) our fast, open-source search engine on your own infrastructure.
79+
🪨 Prefer to self-host? [Download and deploy](https://www.meilisearch.com/docs/learn/self_hosted/getting_started_with_self_hosted_meilisearch?utm_campaign=oss&utm_source=github&utm_medium=strapi-plugin-meilisearch) our fast, open-source search engine on your own infrastructure.
8080

8181
### 🏃‍♂️ Run Strapi <!-- omit in toc -->
8282

@@ -427,24 +427,26 @@ The options you can set are described in the [`findMany` documentation](https://
427427

428428
**Common use cases**
429429

430-
If you are using the [🌍 Internationalization (i18n)](https://docs.strapi.io/developer-docs/latest/plugins/i18n.html) plugin, an additional field `locale` should also be added in `entriesQuery`.
430+
If you are localizing your Strapi content, an additional field `locale` should also be added in `entriesQuery`.
431431

432-
⚠️ Warning: if you do not specify `locale: "all"` in `entriesQuery`, you may not index all available entries, potentially leading to missing products in your search results. To ensure all entries in every language are indexed in Meilisearch, include the `locale` field with the value 'all'.
432+
⚠️ Warning: if you do not specify `locale: "*"` in `entriesQuery`, you may not index all available entries, potentially leading to missing products in your search results. To ensure all entries in every language are indexed in Meilisearch, include the `locale` field with the value 'all'.
433433

434434
```js
435435
module.exports = {
436436
meilisearch: {
437437
config: {
438438
restaurant: {
439439
entriesQuery: {
440-
locale: 'all',
440+
locale: '*',
441441
},
442442
},
443443
},
444444
},
445445
}
446446
```
447447

448+
If you are using Strapi 4 with the [🌍 Internationalization (i18n)](https://docs.strapi.io/developer-docs/latest/plugins/i18n.html) plugin, the `locale` field should be set to `all`.
449+
448450
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](https://docs.strapi.io/dev-docs/api/entity-service/populate) on how it works, and [an example](./resources/entries-query/populate.js) in our resources.
449451

450452
**Example**

resources/entries-query/locale.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = {
44
config: {
55
restaurant: {
66
entriesQuery: {
7-
locale: 'all',
7+
locale: '*',
88
},
99
},
1010
},

server/src/services/meilisearch/config.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,10 @@ export default ({ strapi }) => {
243243

244244
/**
245245
* Remove language entries.
246-
* In the plugin entriesQuery, if `locale` is set and not equal to `all`
247-
* all entries that do not have the specified language are removed.
246+
* In the plugin entriesQuery, if `locale` is set and not equal to
247+
* `all` (used with the i18n plugin for Strapi) or `*` (used with Strapi 5
248+
* native localization), all entries that do not have the specified
249+
* language are removed.
248250
*
249251
* @param {object} options
250252
* @param {Array<Object>} options.entries - The entries to filter.
@@ -258,7 +260,11 @@ export default ({ strapi }) => {
258260

259261
const entriesQuery = contentTypeConfig.entriesQuery || {}
260262

261-
if (!entriesQuery.locale || entriesQuery.locale === 'all') {
263+
if (
264+
!entriesQuery.locale ||
265+
entriesQuery.locale === 'all' ||
266+
entriesQuery.locale === '*'
267+
) {
262268
return entries
263269
} else {
264270
return entries.filter(entry => entry.locale === entriesQuery.locale)

0 commit comments

Comments
 (0)