嗨我在根据相关性对sql查询的结果进行排序时遇到了问题。
这是我目前的疑问。
SELECT author FROM search WHERE MATCH(author,title,series) AGAINST('Anna Selby' in BOOLEAN MODE)
任何人都可以告诉我如何根据相关性对结果进行排序
答案 0 :(得分:2)
您可以选择匹配作为查询的一部分,然后将其作为“分数”返回。然后你可以对它进行排序。 IE:
SELECT
author,
MATCH(author,title,series) AGAINST('Anna Selby' in BOOLEAN MODE) as score
FROM
search
WHERE
MATCH(author,title,series) AGAINST('Anna Selby' in BOOLEAN MODE)
ORDER BY
score
更新:这是加权示例
SELECT
author,
(
(MATCH(author) AGAINST('Anna Selby' in BOOLEAN MODE) * 20) +
(MATCH(title) AGAINST('Anna Selby' in BOOLEAN MODE) * 10) +
(MATCH(series) AGAINST('Anna Selby' in BOOLEAN MODE) * 5)) as score
FROM
search
WHERE
MATCH(author,title,series) AGAINST('Anna Selby' in BOOLEAN MODE)
ORDER BY
score