In my Magento 2 setup, I have products called something like 'Xxxx 1 DS'. When I search for 'xxxx', the product pops up. But when I search for '1 ds', there are no search results. Is this because the search starts with a number? I have set the minimun search characters to 1..
Magento 2 – Fix Search Not Working Properly
catalogsearchmagento2
Related Solutions
With the help of @Axel I was able to fix the issue.
After digging into the Attributes and comparing the settings of the SKU since I could search by that and the settings of Name and Desc. I noticed a few differences.
here is what the SKU was set to
Here is what name was set to before I changed it
This is what I changed Name to
After that I re-indexed the site and then cleared the cache manually via ftp var/cache and deleted all folders in the cache then refreshed the site and tried to search and sure enough it works now.
Thank you Axel for pointing me in the right direction.
I also hope this helps anyone else having an issue with the search.
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");
}
}
}
Best Answer
I do not know your search engine, I suppose that you use Mysql. I cannot comment your question.
But you may try to use SolR or Elastic Search if you want to affine your search experience. It is EE feature, but you can find community module.
You need also to see which raw data is indexed to Mysql / SolR / ElasticSearch to know if the problem occurs on the index level or in the query level.
I test it with ElasticSearch and it works on my side.
I reproduice your error with Mysql search engine.
Resolution :
The data indexed (catalogsearch_fulltext_scope1) is :
The SQL query for 'xxxx' request :
The SQL query for '1 ds' request:
If you check Mysql documentation, there are two parameters for Configuring Minimum and Maximum Word Length :
http://dev.mysql.com/doc/refman/5.7/en/fulltext-fine-tuning.html
So edit your my.cnf file, add these parameters :
Restart mysql
Rebuild your index
Then you will see your product on the search result page.