I get complaints from my users that they can’t search on three letter words like “eye”. For years I was under the assumption that it’s impossible with mySQL. Today I decided that I better ask the experts to see if I’m wrong. Here is the current query that I have in place. Please advise.
Thanks!
SELECT tID, date_format(date, ‘%m-%d-%Y’) as date, viewed, summary, MATCH (summary,testimony,keywords) AGAINST (‘$q’) AS score FROM testimonies WHERE MATCH (summary,testimony,keywords) AGAINST (‘$q’) and approved = ‘Yes’ order by score desc limit 50
It certainly is possible with MySQL. There is an option ft_min_word_length you can put in the [mysqld] section of your my.ini and set it to the minimum length you want the full text search to be able handle (so in your case ft_min_word_length = 3).
Ok, it looks like these types of changes require a restart of the server. I pay a monthly hosting fee and so I don’t have physical access to reboot the server on my own. What does someone in my situation do?
Rudy, do I need to have my ISP upgrade the mySQL version? Here is my query:
SELECT tID, date_format(date, ‘%m-%d-%Y’) as date, viewed, summary, LIKE (summary,testimony,keywords)
AGAINST (‘eye’) AS score FROM testimonies WHERE LIKE (summary,testimony,keywords) AGAINST (‘eye’)
and approved = ‘Yes’ order by score desc limit 50;
Response:
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘upgrade’ at line 1
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘LIKE’ at line 1
I am familiar with using like by itself, but maybe in a query like this, where multiple columns are being examined, I have the format wrong:
SELECT tID, date_format(date, ‘%m-%d-%Y’) as date, viewed, summary, LIKE (summary,testimony,keywords)
AGAINST (‘eye’) AS score FROM testimonies WHERE LIKE (summary,testimony,keywords) AGAINST (‘eye’)
and approved = ‘Yes’ order by score desc limit 50;
SELECT tID
, DATE_FORMAT(date,'%m-%d-%Y') as date
, viewed
, summary
, CASE WHEN summary LIKE '%eye%' THEN 1 ELSE 0 END +
CASE WHEN testimony LIKE '%eye%' THEN 1 ELSE 0 END +
CASE WHEN keywords LIKE '%eye%' THEN 1 ELSE 0 END AS score
FROM testimonies
WHERE approved = 'Yes'
AND ( summary LIKE '%eye%'
OR testimony LIKE '%eye%'
OR keywords LIKE '%eye%' )
ORDER
BY score DESC LIMIT 50;
you could run this whenever the user’s search term is a single word of less than 4 cfharacters, and continue to use the MATCH query for other search terms