Smile-SA / elasticsuite

Smile ElasticSuite - Magento 2 merchandising and search engine built on ElasticSearch
https://elasticsuite.io
Open Software License 3.0
763 stars 342 forks source link

GraphQl. How can I switch to use option id for filtering instead of option name. #3415

Open zakdma opened 1 month ago

zakdma commented 1 month ago

Hi! I'm creating the multi-language site using Nuxt as front and Magento as back communicating using GraphQl. ElasticSuite is installed on it. ElasticSuite replaced Magento core search implementation to use filtering by attribute option name rather than option id. It's ok in general but creates problems when using multiple languages where attribute options have different translations. So when I switched to another language filters in the command line did not work because of different options names in different languages. I want to switch to use option ids as filter values instead of names but can't find such settings in ElasticSuite configuration. Could you please advice the best approach how to switch to use option ids programmatically? I tried to plugin return \Smile\ElasticsuiteCore\Helper\Mapping::getOptionTextFieldName to return $fieldName and actually its working when the index already exists. But index is broken after reindex.

romainruaud commented 1 month ago

Hi @zakdma ,

we have plenty of headless multi-language websites running Elasticsuite through the GraphQl API and we did not notice this kind of issues.

Could you please share more details about what you consider as malfunctioning ?

Please share as well screenshot of your attributes configurations.

Regards

zakdma commented 1 month ago
  1. Install vanilla Magento 2.4.7 with OpenSearch as a searching engine
  2. Create one more store view under default store group. Name it "Ukrainian" and "ua" is the store view code https://prnt.sc/HFV6IYkcE5Kr
  3. Edit default Color attribute and add two options "Red" and "Black" with Ukrainian translations "Червоний" and "Чорний" respectively. https://prnt.sc/zHJaib-f-ony
  4. Add Color attribute to Default attribute set.
  5. Create several simple products under some category with attribute color filled up.
  6. Instal ES composer require smile/elasticsuite ~2.11.0
  7. Configure it properly according to docs
  8. Reindex all and clear cache
  9. Open front and go to category with products
  10. Select Red in the layered navigation left panel https://prnt.sc/-XxKaMZdoUXO
  11. Switch to Ukrainian store view https://prnt.sc/Cahvahc0HIU4
  12. See incorrect filter without Red attribute value selected https://prnt.sc/Le6ozzCfe6d7

The problem is that attribute option text is used for filtering, not option_id. So switching to another language will break filtering because color=Red is not correct option value for Ukrainian store view. It should be color=Червоний instead. We need to preserve filtering during store view (actual language) switching. So it would be good to use option_id as a attribute value for filtering (as vanilla Magento does) color=5 This ID will not change between languages. But looks like ES don't allow us to change filtering back to use option_id. I'm looking for possibility how to do that or even better if you add this to configuration.

Thank you.