0

In Magento 2.1 custom search engines were introduced, so that MySQL could be replaced with ElasticSearch in EE.

My own search adapter works well in the search but now I realized that it is also used to fetch filters in layered navigation on category pages.

This leads to an error if my search result does not contain "buckets" for filterable attributes, like this:

Exception #0 (Magento\Framework\Exception\StateException): Bucket does not exist
#0 [...]/var/generation/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection/Interceptor.php(115): Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection->getFacetedData('style_bags')

While it makes sense to use the search adapter here, my problem is that it does it with the exact same method in Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection that is also used to fetch search results.

This does not work because I distinguish between attributes configured as filterable in search and as filterable in categories, so the normal search result does not contain the buckets that are needed on the category page.

I'll probably implement a switch based on the current controller, although that's not the cleanest solution.

But my question for now is: Is it really necessary to use the search engine in layered navigation or is there a way to fall back to the old method?


Update

It turns out that I get enough information in the $request parameter passed to the query method of my adapter implementation to figure out the context:

debugger screenshot

This makes at least a cleaner solution for my switch.

But when I try to fall back to the default MySQL adapter like this (with adapter injected as \Magento\Framework\Search\Adapter\Mysql\Adapter\Proxy):

if ($request->getName() === 'catalog_view_container') {
    return $this->mysqlAdapter->query($request);
}

there are errors in other places like Magento\Framework\Search\Dynamic\IntervalFactory where my adapter is still used based on di.xml and the system configuration.

1

Magento 2 have layered navigation on search result page too. If you do not cover filtering and aggregation in your adapter this functionality will brocken, so you still need it not only for category page

  • Thanks for the clarification, I guess I'll have to accept that it's not possible. – Fabian Schmengler Sep 26 '16 at 13:29
  • I am getting this error in brand page. When I open particular brand. I am getting this error any idea ? – David Coder Sep 20 '18 at 5:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.