Listed on this question:
MySQL problem – COMPLETE server overrun! Please advise
are all my server details, so I don’t have to re-write them here.
So I’m having a PHP script which interacts with a mysql DB.
2 days ago, due to many requests from my users, I have switched from clasic “select * from table where column like ‘blabla’ and column like ‘lablab'” to the fulltext search.
Indexed, tested, good to go.
2 days on the job, already received a bag of complains.
Searches are indeed better, that is if you use full words… 🙁
try searching for “apple” and you find almost the same results.
try searching for “apple computer at low prices” and the fulltext search is WAY above any LIKE search
try searching for “ple” and you get a full list of results with the classic method… but a big fat “Nothing found” text laying in front of you with the fulltext search…
Sorry for making it sound so poetic up to this point… 😐
Is there any workaround for this? making the fulltext use some freakin’ wildcards? like %foo% should bring me ffoork, flfooor etc…
And for those of you asking, yeah I don’t really know my way around mysql further than syntax, simple expressions and basic functions.
Please help me with a code snippet or link to some method of working this out…
If possible, i would rather not complicate my existence with some 3rd party mysql search engine but as a last resort…
Thank you very much in advance!
Cheers!
Sorry, I forgot to put my code up:
$query="SELECT *,
CASE when title like '%".$s."%' then 1 else 0 END as titlematch,
CASE when tags like '%".$s."%' then 1 else 0 END as tagsmatch,
MATCH (title, tags) AGAINST ('".$s."') AS relevance
FROM videos
WHERE MATCH(title, tags) AGAINST ('".$s."' IN BOOLEAN MODE)
HAVING relevance > 0
ORDER by titlematch desc, tagsmatch desc, relevance desc, `datetime` desc, `views` desc
";
If you are already using boolean mode, you can update your PHP code to automatically add wildcards around the search string inside of
AGAINST(...). This should solve your problem for single-word searches.You could also add wildcards around each single word in case of multi-word searches, but I’d recommend doing some testing with real data (e.g. commonly searched keywords, if you log them) in order to make sure that current result relevancy is not impacted.
Update: try the following: