Magento 2 – Fix Search Not Working Properly

catalogsearchmagento2

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..

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 :

*************************** 1. row ***************************
   entity_id: 45
attribute_id: 73
  data_index: Xxxx 1 DS

The SQL query for 'xxxx' request :

SELECT `main_select`.`entity_id`, MAX(score) AS `relevance` FROM (SELECT `search_index`.`entity_id`, ((0) + LEAST((MATCH (data_index) AGAINST ('xxxx*' IN BOOLEAN MODE)), 1000000) * POW(2, search_weight)) AS `score` FROM `catalogsearch_fulltext_scope1` AS `search_index` LEFT JOIN `catalog_eav_attribute` AS `cea` ON search_index.attribute_id = cea.attribute_id LEFT JOIN `cataloginventory_stock_status` AS `stock_index` ON search_index.entity_id = stock_index.product_id AND stock_index.website_id = 0 WHERE (stock_index.stock_status = 1) AND (MATCH (data_index) AGAINST ('xxxx*' IN BOOLEAN MODE))) AS `main_select` GROUP BY `entity_id` ORDER BY `relevance` DESC LIMIT 10000

The SQL query for '1 ds' request:

SELECT `main_select`.`entity_id`, MAX(score) AS `relevance` FROM (SELECT `search_index`.`entity_id`, ((0) + LEAST((MATCH (data_index) AGAINST ('1 DS' IN BOOLEAN MODE)), 1000000) * POW(2, search_weight)) AS `score` FROM `catalogsearch_fulltext_scope1` AS `search_index` LEFT JOIN `catalog_eav_attribute` AS `cea` ON search_index.attribute_id = cea.attribute_id LEFT JOIN `cataloginventory_stock_status` AS `stock_index` ON search_index.entity_id = stock_index.product_id AND stock_index.website_id = 0 WHERE (stock_index.stock_status = 1) AND (MATCH (data_index) AGAINST ('1 DS' IN BOOLEAN MODE))) AS `main_select` GROUP BY `entity_id` ORDER BY `relevance` DESC LIMIT 10000

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 :

ft_min_word_len = 1
innodb_ft_min_token_size = 1

Restart mysql

service mysql restart

Rebuild your index

bin/magento indexer:reindex

Then you will see your product on the search result page.

Related Topic