Mysql Search for Domain Names

折月煮酒 提交于 2019-12-14 03:09:32

问题


I have a table full of domain names. I'd like to do a search that returns some kind of relevancy results on it. My problem, is that if I do a search for "cool" I want it to return "cooldomain.com", which a fulltext search, unless I'm doing it wrong, will not.

Are there any fulltext options I'm unaware of that will accomplish this? If not, how would I go about doing it?


回答1:


I'd use LIKE here, fulltext search is for matching against full words or expressions, query expansion, etc. And I think the * operator can only be used as a suffix when using MATCH, so you'll miss imcool.com...

I think you'll have to gather more information to make a relevancy sorting.

Edit: If you want to use an index, you can also store the words of the domain in another column, and use the power of fulltext search on this one...




回答2:


Good old WHERE domain LIKE '%cool%' will match, but doesn't return "relevancy" -- I'm not sure how you'd define that.




回答3:


Try something like

SELECT * FROM domains WHERE domain_name LIKE 'cool%';



回答4:


You will need to set a FULLTEXT index to your table and then do something like this:

SELECT *, MATCH(domain_name) AGAINST ('{search term here}' IN BOOLEAN MODE) as Relevance 
FROM domains 
WHERE MATCH (domain_name) AGAINST('{search term here}' IN BOOLEAN MODE) 
ORDER BY Relevance DESC


来源:https://stackoverflow.com/questions/989362/mysql-search-for-domain-names

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