I'm doing a MySQL search using MATCH/AGAINST IN BOOLEAN MODE, but I need that the word's order matters.
Assuming that I have the following content on the column "names" on table "users":
+---------------------------------+
| names |
+---------------------------------+
| RONSON SIMPSON HOMER JAY |
| SIMPSON RONSON HOMER JAY |
| RONSON SIMPSON JAY HOMER |
| SIMPSON RONSON JAY HOMER |
+---------------------------------+
If I'm looking for SIMPSON HOMER, then I need that the very first result be:
FYI, now I'm using the following SQL query:
SELECT *, MATCH(names) AGAINST('+SIMPSON +HOMER') AS relevance FROM users WHERE MATCH(names) AGAINST('+SIMPSON +HOMER' IN BOOLEAN MODE) HAVING relevance > 0.2 ORDER BY relevance DESC, names ASC LIMIT 30;
I'm asking because I didn't find a good answer on SOF or the rest of the internet - the most closest topic was this: MySQL order by "best match", but answers aren't working to me.
I also apologize for the bad example.
Please, no %LIKE% suggestions, because performance of the query is important in my environment
The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:
SELECT
*,
MATCH (users.names) AGAINST ('+SIMPSON +HOMER') AS relevance
FROM
users
WHERE
MATCH (users.names) AGAINST ('+SIMPSON +HOMER' IN BOOLEAN MODE)
HAVING
relevance > 0.2
ORDER BY
relevance DESC,
users.names ASC LIMIT 30