5

When i search for any string, the relevance search result not working properly.Can you guys please look into in the attached image?

I have enable name and sku for the search.

enter image description here

To reproduce this issue I have exported my products and import in fresh Magento and still facing the same problem. so now there are no any extensions and design there.

My Magento version is 2.2.3

  • Hey !!!! anyone has idea about this? Please help me! – Sunny Rahevar Nov 29 '18 at 12:18
  • are you using MySQL search or Elasticsearch? – Abhishek Panchal Nov 29 '18 at 15:42
  • There is default Magento MySQL search. – Sunny Rahevar Nov 30 '18 at 6:05
  • @SunnyRahevar did u get the solution? – Ash-b Jan 21 at 4:20
0

I had similar issue when I tried to use curl command with search query, it was giving me proper result and not in Magento listing. Try below code by overriding Block file.

di.xml

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
    <preference for="Magento\CatalogSearch\Block\Result" type="Vendor\Module\Block\Result" />
</config>

Result.php

<?php 
namespace Vendor\Module\Block;

use Magento\Framework\View\Element\Template;

class Result extends \Magento\CatalogSearch\Block\Result
{   
    protected function _construct()
    {
        $this->setModuleName('Magento_CatalogSearch');
        parent::_construct();
    }

    protected function _getProductCollection()
    {
        if (null === $this->productCollection) {
            $this->productCollection = $this->getListBlock()->getLoadedProductCollection();
        }
        try {
            $block = $this->getLayout()->createBlock('Magento\Catalog\Block\Product\ProductList\Toolbar');

            $dir = $this->getRequest()->getParam('product_list_dir');
            if(!isset($dir)){ $dir = 'DESC'; }
            if ($block->getCurrentOrder()) {
                switch ($block->getCurrentOrder()) {
                case 'relevance':
                    $this->productCollection->setOrder('relevance', $dir);
                    break;
                case 'name':
                    $this->productCollection->setOrder('name', $dir);
                    break;
                case 'price':
                    $this->productCollection->setOrder('price', $dir);
                    break;
                default:
                    $this->productCollection->setOrder('relevance', $dir);
                    break;
                }
            }
            return $this->productCollection;
        } catch (\Exception $e) {
            $this->logger->error('Fault Code: ' . trim($e->getCode()));
            $this->logger->error('Fault Reason: ' . trim($e->getMessage()) . "\n");
        }
    }
}
  • Thank you for your answer. I have tried your code and find that i could not get anything in "$this->productCollection = $this->getListBlock()->getLoadedProductCollection();" could you tell me what is the issue behind that? – Jaimin Dec 7 '18 at 6:15

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.