MYSQL: Like Method, Similar Words - But Don't Show the Searched Word

此生再无相见时 提交于 2019-12-10 22:52:17

问题


actually i use this method to show similar words for a search request..

$query = "SELECT * FROM searches WHERE Query LIKE '%$search%' ORDER BY Query"; 

if someone searches for "nelly" it looks up in the database for similar words

"nelly furtado, nelly ft. kelly"...

but i dont want to show up the searched word..

example: you've searched for nelly - try this too: nelly, nelly furtado, nelly ft.,

the bold word should not showed up again, because it's the searched word.. is there maybe a method with MATCH AGAINST? thank you!


回答1:


Couldn't you just do something like ...WHERE Query LIKE "%$search%' AND Query <> '$search'...?

Case-insensitive: Query LIKE "%$search%' AND STRCMP(Query, '$search') == 0




回答2:


Leniel - It might be due to capitalization that search term is still showing up, i.e. *LIKE "nelly"* will find "nelly", "Nelly", "NeLlY", etc. whereas * <> "nelly"* will only exclude "nelly" (lowercase) from the results.

Perhaps NOT LIKE would yield better results, or str_to_lower your input before it leaves PHP and compare it to LOWER(column_name) to match all cases.



来源:https://stackoverflow.com/questions/2546892/mysql-like-method-similar-words-but-dont-show-the-searched-word

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!