Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Minimal Query Length] issue for search strings of 1 - 2 characters #4080

Open
ADDISON74 opened this issue Jul 4, 2024 · 4 comments
Open

Comments

@ADDISON74
Copy link
Contributor

There is an issue related to the "Minimal Query Length" value set in the Backend. In order to reproduce this issue follow these steps

  1. Go to the Backend > System > Configuration > Catalog > Catalog Search

  2. Set "Minimal Query Length" to 3

  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]

  4. Go to the Backend > System > Configuration > Catalog > Catalog Search

  5. Set "Minimal Query Length" to 4

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

@SuSiSonnenschein111
Copy link

SuSiSonnenschein111 commented Jul 11, 2024

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

@ADDISON74
Copy link
Contributor Author

ADDISON74 commented Jul 11, 2024

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

@ADDISON74
Copy link
Contributor Author

ADDISON74 commented Jul 11, 2024

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:

/**
* Is a minimum query length
*
* @return bool
*/
public function isMinQueryLength()
{
$minQueryLength = $this->getMinQueryLength();
$thisQueryLength = Mage::helper('core/string')->strlen($this->getQueryText());
return !$thisQueryLength || $minQueryLength !== '' && $thisQueryLength < $minQueryLength;
}

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.

@sreichel
Copy link
Contributor

Pls check emails I've sent - and close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants