meilisearch / strapi-plugin-meilisearch

A strapi plugin to add your collections to Meilisearch
https://meilisearch.com
MIT License
223 stars 58 forks source link

Strapi Nested Relation Field , attributes not appearing #758

Open da-kicks-87 opened 1 year ago

da-kicks-87 commented 1 year ago

Description I have connected Strapi with Meilisearch official plugin.

I am testing in the Meilisearch Mini Dashboard. My Strapi "Product" content type appears in the search results. However for its Relationship Field "Product Variants" the array's object is missing the "Photos" attribute and more.

Why is this? Is there a limit on the nested results?

Screenshots or Logs

Environment

bidoubiwa commented 1 year ago

Hey @da-kicks-87 to add the nested fields in your final document, you should use the populate parameter from strapi. See this section https://github.com/meilisearch/strapi-plugin-meilisearch#-entries-query

da-kicks-87 commented 1 year ago

@bidoubiwa I am using GraphQL and not REST API for Strapi so using populate didn't cross my mind. I have tried your suggestion and i still doesn't work.

Here is my code from plugin.js

meilisearch: { config: { // Your meili host host: env('MEILISEARCH_HOST'), // Your master key or private key //apiKey: env('MEILISEARCH_API_KEY'), product : { entriesQuery: { populate: ['product_variants.photos', 'photos'], }, }, }, }

As an alternative solution I am calling GraphQL from my search results page to get the the product_variant images and then matching the id with my base product with javascript loop.

This redundant since Meilisearch should be able to get the nest data.

bidoubiwa commented 1 year ago

Hey @da-kicks-87, unfortunately we cannot do that as we cannot know to what extent we add the relationships? Do we also include the relations of the relations (etc etc...)? Adding listeners to these relationships would also be a mess. Unless we create a specific setting for it which feel free to suggest a solution for.

About the populate rule, I had a hard time making it work as well but it is meant for this exact purpose. Could you ask on strapi's side why it doesn't work?

haZya commented 1 year ago

Hey @da-kicks-87

Did you check if the attribute that you aren't getting is private or not? Because private attributes are not indexed AFAIK.

I wish this wasn't the case or there was an option to still index private attributes. This is because if I didn't want to get the private attribute value I could remove it from displayedAttributes or do a hacky workaround where I could use transformEntry to return null for that attribute that needs to be private. But there is no way to index that attribute without removing private in which case I'll have to sanitize it manually from the Strapi side.

@bidoubiwa Is this the case? Or am I missing something?

bidoubiwa commented 1 year ago

Hey @haZya ! This was introduced in this PR https://github.com/meilisearch/strapi-plugin-meilisearch/pull/703/files

Could you create a new issue with your request? We can create a setting to allow private fields