magento-lts
magento-lts copied to clipboard
[Minimal Query Length] issue for search strings of 1 - 2 characters
There is an issue related to the "Minimal Query Length" value set in the Backend. In order to reproduce this issue follow these steps
-
Go to the Backend > System > Configuration > Catalog > Catalog Search
-
Set "Minimal Query Length" to 3
-
In the Frontend search for a => There are 1173 results in my case [incorrect] ab => There are 524 results in my case [incorrect] abc => There are no results [correct]
-
Go to the Backend > System > Configuration > Catalog > Catalog Search
-
Set "Minimal Query Length" to 4
-
In the Frontend search for a => There are 1173 results in my case [incorrect] ab => There are 524 results in my case [incorrect] abc => Warning message "Minimum Search query length is 4" [correct] abcd => There are no results [correct]
As you can see, OpenMage always returns results for a string consisting of one or two characters, no matter if you set the minimal query length to >=3 . This issue is a legacy from Magento.
Thinks this is a known MySQL problem that cant be fixed via code change ... see https://magento.stackexchange.com/questions/7619/magento-search-less-than-4-characters
@SuSiSonnenschein111 - Very good observation, I did not expect it to depend on the configuration of the database server. I will check and if it is confirmed then an information message must be added under that option in the Backend to avoid confusion.
According to MariaDB docs, ft_min_word_len value must be between 1 and 84. The default value is 4. In MySQL 8.4 docs the maximum value is 82.
I set the value 1 for fn_min_word_len in my.cnf.
In OpenMage I set the value 3 for Minimal Query Length. I reindex data for "Catalog Search Index". I had to repair the table catalogsearch_fulltext too.
It would be natural to get in the Frontend the error message "Minimum Search query length is 3" if I search for 1 or 2 characters, but it is not displayed and I am getting a long list of products, the same behavior like in my initial report.
My opinion is that it is a problem in the OpenMage source code:
https://github.com/OpenMage/magento-lts/blob/0b27c5ff37ef14488e4dd8f408cb439f959dcec8/app/code/core/Mage/CatalogSearch/Helper/Data.php#L96-L106
this method returns a wrong result. Let's take as example a few values:
$minQueryLength = 4 (the one set in the Backend) $thisQueryLength = 1 (the query string used in the Frontend)
the result is 1 which is not correct, this is why I am getting the products list instead of the error message.
Let's go further:
For $thisQueryLength = 1, 2 and 3 the result is 1. Starting with 4 there is no result. Try the test here
https://onlinephp.io?s=s7EvyCjg5VIAIpXczLzA0tSiSp_UvPSSDAVbBRNrsHhJRmYxVomi1OLSnBIgXxFDTU0NhnmKtrYK6uoKamqYJtqgKwaZz8uVmpyRD7PFGgA%2C&v=8.2.19
The MySQL config variable is not processed in the whole CatalogSearch module.
Pls check emails I've sent - and close it.
@addison74 i cant remember, but i think i can be fixed with search sttings (fulltext, ...).
Please re-open if it is still an issue.