elasticsuite
elasticsuite copied to clipboard
when we use optimizer then other custom sortings are stopped working on the list page.
Preconditions
Magento Version : Magento 2.3.7 EE
ElasticSuite Version : 2.9.0
Environment : Developer
Third party modules : No any third party module
Steps to reproduce
- We installed the elastic suite and configured it and it is working fine.
- After that we create a new optimizer with the decimal type of attribute which is also working fine on the category page.
- But on the category page, other sorting options have stopped working.
Expected result
- All the other sorting options should work on the category page with the optimizer.
-
For sorting, we have applied the ORDER BY in the collection for the category page for our custom sorting which is last purchase date but this collection is being overwritten by the optimizer.
-
We can not create the optimizer for our custom sorting because we are applying sorting in the collection on the category page.
Please guide us so we can resolve this issue.
Hello @manishgoswamig,
Could you please provide more details with screenshots about the configuration of your optimizer?
Also, provide a way how you exactly implement your custom sorting in the collection (di.xml, etc). Because normally Optimizers should have any effects on sorting, so maybe your implementation starts work too early or too late.
BR, Vadym
Hi @vahonc,
Thanks for the active response, I am trying to apply sorting using collection and for that, I have updated the below files. When I am trying to print my query in direct sql I am getting the result as I want but on the frontend category page, there is a different result.
Path : app/code/Namespace/Modulename/etc/module.xml
<?xml version="1.0" ?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="Namespace_Modulename" setup_version="1.0.0"> <sequence> <module name="Magento_Eav"/> </sequence> </module> </config>
Path : app/code/Namespace/Modulename/etc/frontend/di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Magento\Catalog\Block\Product\ProductList\Toolbar" type="Namespace\Modulename\Block\Catalog\Product\ProductList\Toolbar" /> <preference for="Magento\CatalogSearch\Block\Result" type="Namespace\Modulename\Block\CatalogSearch\Result" /> </config>
screenshot :
Path: app/code/Namespace/Modulename/Block/Catalog/Product/ProductList/Toolbar.php
}elseif($this->getCurrentOrder() === 'previously_purchased'){ $collection->addAttributeToSelect('score_precise','left'); $collection->getSelect()->order('order_date DESC'); }else{ $collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection()); }
Please guide me so that I can resolve it :) . `
Hi @vahonc,
Do you have any idea about this issue?
Hello @manishgoswamig,
It looks like you have implemented your custom sort orders at the SQL level.
This is not the way to go with Elasticsuite since
- Elasticsuite first performs an Elasticsearch request grabbing the desired amount of products per the toolbar pagination settings and applying the toolbar / customer selected sort order parameters
- this results in a, say collection of 20 products, that are then hydrated against the Magento SQL DB
So your custom sort orders will only be able to re-sort "locally" those 20 products. The way to go is to make sure the data you want to sort your products against is indexed into Elasticsearch along with the other product data.
If you want to have some secondary sorting options when you are sorting by an attribute (for instance when you sort by "brand", you seem to want to sort also by "part" number), you will need to do some additional trickery when Elasticsuite builds its sort parameters, by changing the behavior of \Smile\ElasticsuiteCore\Search\Request\SortOrder\SortOrderBuilder::buildSordOrders.
Regards
This issue was waiting update from the author for too long. Without any update, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now. Please don't hesitate to comment on the bug if you have any more information for us; we will reopen it right away! Thanks for your contribution.