Mysql find keywords in text

99封情书 提交于 2019-12-06 07:16:49

问题


I have a Mysql InnoDB table with 10k keywords and I want to match them against several texts.

Some keywords have several words and I only want exact matchs.

Example: Keywords - brown fox, lazy cat, dog, fox, rabbit

Text - The quick brown fox jumps over the lazy dog

I want the query to return - brown fox, dog, fox


回答1:


SELECT * FROM tenKTable 
WHERE 'The quick brown fox jumps over the lazy dog' LIKE CONCAT('%',keyword,'%')

Source: MySQL SELECT query string matching




回答2:


Here's one idea:

SELECT keyword 
FROM Keywords
 JOIN (SELECT 'The quick brown fox jumps over the lazy dog' as col) k
   on k.col like Concat('%',keywords.keyword,'%')

And the SQL Fiddle.

Good luck.



来源:https://stackoverflow.com/questions/14594890/mysql-find-keywords-in-text

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