我试图在三个字段标题,作者和文本上创建关键字搜索。我希望他们按照相关性排序,所以我在任何一个字段中给一个匹配点。我也有一个名为标签的表格,它在每行中存储一个故事的特定标签。如果标签上有匹配项,我会在标签的使用次数上增加相关性。当用户输入搜索时,他可以输入一系列关键字。我正在考虑使用字符串爆炸并使用for循环为每个关键字添加下面select语句中的代码。 这似乎相当复杂,所以我想知道是否有更好的方法来做到这一点?Mysql php关键字搜索
select text, ((case when S.sid in (select sid from tags where tahname like 'db')
then (select uses from tags T where S.sid = T.sid and tagname like 'db') +
(case when title like '%db%' then 1 else 0 end) +
(case when author like '%db%' then 1 else 0 end) +
(case when text like '%db%' then 1 else 0 end)) as relevance
from stories S
order by relevance desc
谢谢。
你好,感谢您的答复。我是mysql新手,所以我不太清楚MyISAM表和InnoDB表之间有什么不同,但我使用的是InnoDB表。我认为当你说(来自MySQL 5.6)它还不能用于InnoDB表? – user1832628
好的,这是他们为下一个MySQL版本开发的新功能。 –