我使用以下查询来搜索表中的记录:
SELECT * FROM posts WHERE MATCH (title) AGAINST ('$q') LIMIT 15
它返回前15个结果,如何按最大匹配数量的顺序对其进行排序?
答案 0 :(得分:1)
SELECT *, MATCH (title) AGAINST ('$q') AS mat
FROM posts
WHERE MATCH (title) AGAINST ('$q') ORDER BY mat LIMIT 15
ORDER BY mat DESC
您可以添加ORDER BY mat DESC
或 ORDER BY mat
答案 1 :(得分:1)
试试这个
SELECT *,MATCH (title) AGAINST ('$q') AS relevance FROM posts WHERE MATCH (title) AGAINST ('$q') ORDER BY relevance DESC LIMIT 15