Hi,
Magento 2.x search not performing well, when we use any number/digit with the name.
For example, we are selling apple iphone on our site, and so products names are , iPhone 4, iPhone 5, iPhone 6....
And when we search for iPhone 4, it shows all the result related to iPhone not only iPhone 4.
I understand about relevance result, but it should show iPhone 4 first and then rest on...
but it does not matter, either iphone 4, iPhone 5, iPhone 6... It's just searching based on iPhone...
I have tried with text value then it searching well,
--not working fine with numeric and text combination
http://www.nunutz.com/catalogsearch/result/?q=iphone+5
--- working fine if text combination only.
http://www.nunutz.com/catalogsearch/result/?q=Drone+Batteries
Can any one help to sort out this issue?
Thanks
1.
Hi @palvinder03,
It's not a bug but rather a limitation of MySQL.
Under the hood, Magento Search with MySQL search engine uses MySQL Full-Text Search. And out of the box, MySQL limits a length of a phrase being indexed to 3 symbols.
So, Magento doing its work well in this case (I believe this, but if not then we should fix it), but MySQL actually just ignores a search string which is shorter than configuration value.
This limitation described in the MySQL documentation: "Fine-Tuning MySQL Full-Text Search" as well as the steps needed to customize this behavior: "Configuring Minimum and Maximum Word Length":
The minimum and maximum lengths of words to be indexed are defined by the innodb_ft_min_token_size and innodb_ft_max_token_size for InnoDB search indexes, and ft_min_word_len and ft_max_word_len for MyISAM ones.
But take into account the notice from MySQL on the top of that page:
Full-text search is carefully tuned for effectiveness. Modifying the default behavior in most cases can actually decrease effectiveness. Do not alter the MySQL sources unless you know what you are doing.
Be careful with this change as it may decrease your site performance.
I use Sphinx search with the Mirasvit extension. But I have the same issue. as long as we use text it uses an AND search. As soon as I search for something with a number in it it changes to an OR search query. Very annoying. It looks like it's not engine related or something.
I also talked to Mirasvit about this extensively. They claim to use only AND queries for everything though.
@igrybkov
yes i have tried , but it does not seems the issue of mysql,
It seems issue with the magneto query or Operator (AND or OR),
And if its happen due to to mysql then ajax search should not show proper result, for example i used ajax search my site, it showing accurate result in its search drop down, check in attached screenshot

Could you please suggest any idea how we can fix this for our site if possible?
Thanks
Hi @Frits1980,
On the default MySQL configuration, this case will be definitely reproduced due to the reason described above. It's known and expected behavior.
If the issue will be reported back after MySQL configuration change then it should be checked and fixed.
Regarding your case, we're not responsible for 3rd-party extensions and cannot help you with their work. You can talk with extension vendor to help him identify the issue, and they may fix it in their extension or report it to Magento in the manner which is not related to their extension but describes an issue with the Magento itself, and we'll proceed with it as with any general issue report.
@palvinder03,
The "Ajax search" is actually not a search at all (if it's the search suggestions functionality which is works on default search input and not something another), but rather a cached search queries with cached search result numbers. It doesn't make a search query and looking for the input phrase in with a "LIKE" query through cached results.
Just to clarify, did you make a configuration change? It requires three steps:
[mysqld]
innodb_ft_min_token_size=1
ft_min_word_len=1
php bin/magento indexer:reindex catalogsearch_fulltextHey @palvinder03 what we recommend you to do is to make some customization for your specific business case.
For example, you could slightly modify the original Search Phrase provided by user and substitute
iPhone 4 -> iPhone4
iPhone 5 -> iPhone5
and so on
We already have functionality which changes the original search query. This is how Magento Synonyms are implemented.
You can look at the code here:
https://github.com/magento/magento2/blob/99e85cbc45223baa3551e4c534b650c0d2c6358b/app/code/Magento/Search/Adapter/Query/Preprocessor/Synonyms.php
Also, you can add a searchable attribute, which would be invisible on front-end, thus it would not change your front-end look and feel. So, its content will get to the product index, and there would be possible to find a product based on its content.
For the "iPhone 4" product the value of the attribute would be "iPhone4".
Also, you could specify high Weight for this attribute, to make it more influential on the result set, if there would be a match by this attribute.
Doing all the above you will get next result:
Initial search phrase: "buy case for iPhone 4"
would under the hood substituted on "buy case for iPhone4"
And you will have a product with searchable attribute holding value "iPhone4", so this product would be on the top of result set.
@igrybkov Thanks for the most obvious answer there is. You're quite a star in helping people. And you apparently didn't read my post very well. It said: I've had extensive contact with Mirasvit about this issue and they looked into it and it's not there issue. So where do you suppose I should go to get any further? Because if everybody in the world would point at someone else shit never gets solved. So please quit giving senseless replies.
We don't recommend you to change default minimal token size in MySQL configuration because it could lead to performance degradation, as the size of index, depending on your Catalog data could grow drastically.
Also, that could potentially harm the quality and accuracy
At least you should double check on testing environment before making changes to production
@maghamed
Thanks for your response,
I like your your second opinion to create the attribute and set it max.
So i have created a seprated attribute set for my iphone products and create a attribute where i can put
iphone4, iphone5 etc, and did not show on frontend.
So now result is working fine as expected ,
Thanks you saved my time without changing in code or create extra module or change any configuration.
Thanks
@maghamed
Thanks for your response,
I like your your second opinion to create the attribute and set it max.
So i have created a seprated attribute set for my iphone products and create a attribute where i can put
iphone4, iphone5 etc, and did not show on frontend.
So now result is working fine as expected ,
Thanks you saved my time without changing in code or create extra module or change any configuration.
Thanks
@palvinder03 you welcome.
In any case, if you would have further questions regarding search customization. Let us know.
For us (Magento core team) it's pretty interesting how out of the box Search is being used and customized by Community developers
and whether it satisfies your needs.
There are a few things that you can try out if Magento's search is not working as expected. Read this article for details:
https://blog.expertrec.com/magento-search-not-working/
Most helpful comment
I use Sphinx search with the Mirasvit extension. But I have the same issue. as long as we use text it uses an AND search. As soon as I search for something with a number in it it changes to an OR search query. Very annoying. It looks like it's not engine related or something.
I also talked to Mirasvit about this extensively. They claim to use only AND queries for everything though.