Skip to content

Commit 9aa1254

Browse files
authored
Merge pull request #1 from L-Weisz/feat/indexName/handle-multiple-indexNames
Feat/index name/handle multiple index names
2 parents bccdbe3 + d33dd5e commit 9aa1254

File tree

9 files changed

+731
-157
lines changed

9 files changed

+731
-157
lines changed

README.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,9 @@ Settings:
217217

218218
By default, when indexing a content-type in Meilisearch, the index in Meilisearch has the same name as the content-type. This behavior can be changed by setting the `indexName` property in the configuration file of the plugin.
219219

220-
**Example:**
220+
To link a single collection to multiple indexes, you can assign an array of index names to the `indexName` property.
221+
222+
**Example 1: Linking a Single Collection to a Single Index**
221223

222224
In the following example, the `restaurant` content-type in Meilisearch is called `my_restaurant` instead of the default `restaurant`.
223225

@@ -229,7 +231,7 @@ module.exports = () => ({
229231
meilisearch: {
230232
config: {
231233
restaurant: {
232-
indexName: "my_restaurants",
234+
indexName: ["my_restaurants"],
233235
}
234236
}
235237
}
@@ -248,10 +250,10 @@ module.exports = () => ({
248250
meilisearch: {
249251
config: {
250252
shirts: {
251-
indexName: 'products',
253+
indexName: ['products'],
252254
},
253255
shoes: {
254-
indexName: 'products',
256+
indexName: ['products'],
255257
},
256258
},
257259
},
@@ -260,6 +262,25 @@ module.exports = () => ({
260262

261263
Now, on each entry addition from both `shoes` and `shirts` the entry is added in the `product` index of Meilisearch.
262264

265+
**Example 2: Linking a Single Collection to Multiple Indexes**
266+
267+
Suppose you want the `restaurant` content-type to be indexed under both `my_restaurants` and `all_food_places` indexes in Meilisearch. You can achieve this by setting the `indexName` property to an array containing both index names, as shown in the configuration below:
268+
269+
```js
270+
// config/plugins.js
271+
272+
module.exports = () => ({
273+
//...
274+
meilisearch: {
275+
config: {
276+
restaurant: {
277+
indexName: ['my_restaurants', 'all_food_places'],
278+
}
279+
}
280+
}
281+
})
282+
```
283+
263284

264285
**disclaimer**
265286

playground/config/plugins.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ module.exports = ({ env }) => ({
1515
categories: entry.categories.map(category => category.name)
1616
};
1717
},
18-
indexName: "my_restaurant",
18+
indexName: ["my_restaurant"],
1919
settings: {
2020
"searchableAttributes": ["*"]
2121
}
2222
},
2323
"about-us": {
24-
indexName: "content",
24+
indexName: ["content"],
2525
},
2626
homepage: {
27-
indexName: "content",
27+
indexName: ["content"],
2828
},
2929
// host: "http://localhost:7700",
3030
// apiKey: "masterKey"

resources/custom-index-name/custom-index-name.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// `shirts` and `pants` will be indexed in the same `products` index.
2+
// `tops` will also be indexed in a separate `tops` index.
23
module.exports = () => ({
34
//...
45
meilisearch: {
56
config: {
67
shirts: {
7-
indexName: 'products',
8+
indexName: ['products', 'tops'],
89
},
910
pants: {
10-
indexName: 'products',
11+
indexName: ['products'],
1112
},
1213
},
1314
},

server/__mocks__/strapi.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ function createStrapiMock({
3939
ApiKeyIsFromConfigFile: true,
4040
HostIsFromConfigFile: true,
4141
}),
42+
getIndexedContentTypes: () => ['api::restaurant.restaurant', 'api::about.about'],
4243
actionInBatches: mockActionInBatches,
4344
addIndexedContentType: mockAddIndexedContentType,
4445
subscribeContentType: () => {

0 commit comments

Comments
 (0)