SELECT *,
MATCH (`text`) AGAINST ('my work involves for' IN BOOLEAN MODE) `score`
FROM `messages` WHERE MATCH (`must_match`) AGAINST ('my work involves for' IN BOOLEAN MODE)
ORDER BY `score` DESC
所以这里的用户输入是“我的工作涉及”
id text must_match
--- ---- ------
1 my work is to help work,help
2 work involves help involves,work
现在我想要结果,如果 mus_match 列的所有单词在用户输入中匹配 因此,从上一行我们的结果将是第二行
must_match 列将包含文本列中的单词
最佳答案
在花了很多时间之后,我无法为您的任务提出解决方案/解决方法。这背后的主要原因是您的表中有多值属性:must_match
。它包含以逗号分隔的值,并且值的数量也未预定义。
首先,我会要求你通过this link为了实现在列中存储分隔列表的缺点。
id text1 must_match
1 my work is to help work
1 my work is to help help
2 work involves help involves
2 work involves help work
现在,如果您能够在 1NF 中转换您的表并将 must_match
的多个值存储在多行中(如上所述),那么请继续阅读以寻求解决方案,如果不能,请评论背后的原因那个。
解决方案:
select id,text1,
MATCH (text1) AGAINST ('my work involves for' IN BOOLEAN MODE) as score
from t t1
where locate(must_match,"my work involves for") > 0
group by id
having count(*) = (select count(*) from t where id = t1.id);
注意如果id
是一个主键,那么您可以使用text
列也是。group by
希望对您有所帮助!
关于mysql - 必须匹配 MATCH AGAINST mysql 中的所有单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47389603/