tags-table
有三列web, tags, rank
此表已启用FULL TEXT SEARCH
我可以按标签搜索并通过此查询获取网站列表
SELECT * FROM tags-table WHERE MATCH (tags) AGAINST ('search,searchengine,search,web' IN BOOLEAN MODE)
但我希望按其排名来排序结果。我该怎么办?
我也尝试了这个,但它给了别的东西。
SELECT * FROM tags-table WHERE MATCH (tags) AGAINST ('search,searchengine,search,web' IN BOOLEAN MODE) ORDER BY ABS(rank)
由rank
列填充各个站点的排名。例如,google
已获得rank 1
,facebook
获得rank2
,而yahoo
已获得rank 4
,就像剩余网站一样。
tags-table
web | tags | rank
-----------------------------------------------------------------------------------
google.com |search,google,searchengine,engine,web | 1
facebook.com |facebook,social,networking,friends,community | 2
youtube.com |video,youtube,videos,entertainment,media | 3
yahoo.com |yahoo,search,email,news,searchengine | 4
答案 0 :(得分:0)
没有魔术专栏rank
。但是你可以像这样计算相关性(或你称之为排名):
SELECT
*,
MATCH (tags) AGAINST ('search searchengine search web') AS relevance
FROM
tags-table
WHERE
MATCH (tags) AGAINST ('+search +searchengine +search +web' IN BOOLEAN MODE)
ORDER BY
relevance DESC
请注意,第一个MATCH AGAINST
未运行IN BOOLEAN MODE
。这是因为IN BOOLEAN MODE
几乎总是返回1.