Skip to content

Commit 8b98055

Browse files
committed
Add resources with settings examples
1 parent 4c93a8c commit 8b98055

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ By transforming the `categories` into an array of names, it is now compatible wi
291291

292292
Each index in MeiliSearch can be customized with specific settings. It is possible to add your [MeiliSearch settings](https://docs.meilisearch.com/reference/features/settings.html#settings) configuration to the indexes you create using `settings` field in your model's config.
293293

294-
The settings are added when either adding a whole collection to MeiliSearch or when updating a collection in MeiliSearch. The settings are not updated when documents are added through the [`listeners`](-apply-hooks).
294+
The settings are added when either: adding a collection to MeiliSearch or when updating a collection in MeiliSearch. The settings are not updated when documents are added through the [`listeners`](-apply-hooks).
295295

296296
**For example**
297297
```js
@@ -310,6 +310,8 @@ module.exports = {
310310
}
311311
```
312312

313+
[See resources](./resources/meilisearch-settings) for more settings examples.
314+
313315
### 🕵️‍♀️ Start Searching <!-- omit in toc -->
314316

315317
Once you have a collection containing documents indexed in MeiliSearch, you can [start searching](https://docs.meilisearch.com/learn/getting_started/quick_start.html#search).
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Adds the settings specific to this collection in MeiliSearch.
3+
*/
4+
5+
module.exports = {
6+
meilisearch: {
7+
settings: {
8+
filterableAttributes: ['genres'],
9+
distinctAttribute: null,
10+
searchableAttributes: ['title', 'description', 'genres'],
11+
synonyms: {
12+
wolverine: ['xmen', 'logan'],
13+
logan: ['wolverine', 'xmen'],
14+
},
15+
},
16+
},
17+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Imagine if you have a collection restaurant with a category field.
3+
* Category is a collection of its own. They have a many-to-many relationship.
4+
*
5+
* In MeiliSearch you can use filters to for example in our case, only find italian restaurants.
6+
* To be able to do that, you need to provide a list of values and add in the settings the field in `filterableAttributes`.
7+
* See guide: https://docs.meilisearch.com/reference/features/filtering_and_faceted_search.html#configuring-filters
8+
*
9+
* In Strapi, when fetching an entry the many-to-many relationships are inside an object:
10+
*
11+
* {
12+
* id: 1,
13+
* restaurant_name: "The squared pizza",
14+
* category: [
15+
* { id: 1, name: "italian" },
16+
* * { id: 2, name: "French" }
17+
* ]
18+
* }
19+
*
20+
* Since MeiliSearch is expecting `category: ["Italian", "french"]` and
21+
* also `category` to be in `filterableAttributes` we can use the model configuration file to provide all these informations.
22+
*/
23+
24+
module.exports = {
25+
meilisearch: {
26+
settings: {
27+
filterableAttributes: ['categories'], // add categories to filterable attributes.
28+
},
29+
transformEntry({ entry }) {
30+
const transformedEntry = {
31+
...entry,
32+
categories: entry.categories.map(cat => cat.name), // map categories to only have categories name.
33+
}
34+
return transformedEntry
35+
},
36+
},
37+
}

0 commit comments

Comments
 (0)