Catalog search no longer breaks on a trailing operator
Merged PR #1492 fixes MySQL error 1064 when a shopper's search ends with an operator, and finally applies the word limit and minimum word length to every search word, on every database.
A merged pull request fixes a long-standing catalog search bug: MySQL error 1064 on a trailing operator.
The search-suggest request sends the term while the shopper is still typing, so a search
like test - reached the database with a bare trailing -. In MySQL boolean mode that is
invalid syntax and the query failed with error 1064.
What changed
prepareTerms() used to copy every standalone operator and bracket straight into the
boolean-mode query, so test - produced "test" -. The operator support was never
actually usable anyway: an operator only worked as a separate word (-brush was treated
as a phrase), test* never truncated, and PostgreSQL, SQLite and the LIKE search ignored
operators altogether.
Now each word is wrapped in double quotes and any word made up only of operator or bracket
characters is dropped. The result is predictable: test - brush finds products matching
test or brush, and no longer silently excludes brush. On SQLite the same words are
dropped, so test - no longer produces a LIKE value that matches nothing, and that value
no longer starts with a stray space.
Two related limits were also made consistent:
max_query_wordspreviously limited only the terms, not the words bound to the:queryparameter, so the full-text query had no word limit at all. It now has one on every database.min_query_lengthapplied only to the whole search text. Each word shorter than the minimum is now dropped, on every database and for both the full-text query and theLIKEconditions. ALIKEsearch left with no word finds no product, and the “Maximum words count” notice counts the same words the search actually uses.
A search for only operator characters such as --- used to match every product on SQLite;
it now matches nothing, matching MySQL behaviour.
Editor's note.Text prepared with the help of AI and checked against the source before publication. It can still contain mistakes: if you find one, report it.Read the manifesto
Source: MahoCommerce/maho#1492
Does your store still sell?
Tell us where you are starting from: we reply with a first assessment, no strings attached.
Ask for the store assessment