Make it possible to chose which sub-fields of the related collection we should keep
See original GitHub issueProblem
If you have a collection in Strapi that has a relation with another collection, once you index it to MeiliSearch the output is the following:
{
"id": 2,
"name": "Italian",
"restaurants": [
{
"id": 1,
"name": "PetitPatapon",
"description": "Delicieux",
"created_by": 1,
"updated_by": 1,
"created_at": "2021-03-03T12:09:10.979Z",
"updated_at": "2021-03-03T12:09:10.988Z"
},
{
"id": 2,
"name": "LaLoLaLiTa",
"description": "Ma que bello",
"created_by": 1,
"updated_by": 1,
"created_at": "2021-03-03T12:17:46.503Z",
"updated_at": "2021-03-03T12:17:46.515Z"
}
]
},
But for MeiliSearch to create facets the best way would be to transform the restaurants object into the following:
{
"id": 2,
"name": "Italian",
"restaurants": ["LaLoLaLiTa", "PetitPatapon"]
},
Solution
It would be better that on indexation, if a relation is discovered, the user is prompted to chose one field or to ignore the questions.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Control Subfields - OCLC
The subfields included here are used to provide various identifiers, relationships, and sources of terms and codes. They are also used to ...
Read more >Understanding MARC Bibliographic: Parts 7 to 10
In general, every field MUST have a subfield 'a' ($a). One exception that is often seen is in Field 020 (ISBN), when the...
Read more >Ability to search via free text MARC tag and subfields
We would like to have an advanced search option that allows us to enter the MARC tag number (and subfields) for searching, ...
Read more >Psychology subfields
They apply psychological science to understand how we make decisions and perceive our world. Climate and environmental psychology. Climate and environmental ...
Read more >Creating conditional ticket fields - Zendesk help
By limiting the number of fields that initially display, you make it so that agents and end users complete only the fields that...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks to @harish2704 it will become possible to choose your fields by adding a transformer to your collection so that you can change the data before sending it to MeiliSearch.
See #287
example in the restaurant collection.
It will be available next release!
Ok, so for now I found a workaround to make facets on relations work:
When you’ve created your post types go to your strapi
/api/<CONTENT_TYPE>
folder. In there your should find 4 folders:config
controllers
models
services
Go to the
services
folder and open yourposts.js
.In there you can customize how posts are read from the database. As the meilisearch plugin is using the
find()
-Method of your types service, you need to overwrite its functionality like the following:More on customizing your backend: https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html
I think this functionality (lodash and flattening) could be the way for the meilisearch-plugin to provide such functionality as long multi-dimensional searches are not possible by meilisearch itself.
Plugin needs to be changed that it recognizes that the content-type you want to add to meilisearch has relations on other types. Therefor it should be possible to have an UI-PopUp which shows all fields of the type. In there you could choose which fields you want to add to the index. Besides choosing the fields you could override the keys and transformation. Transformation: Use-Cases are Enums and relations. Relations could be flattened to one field, Enums mapped to another value.