我正在使用以下查询来搜索表中的记录:
SELECT * FROM posts WHERE MATCH (title) AGAINST ('$q') LIMIT 15
它返回前 15 个结果,如何按最大匹配数的顺序对其进行排序?
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
尝试这个
SELECT *,MATCH (title) AGAINST ('$q') AS relevance FROM posts WHERE MATCH (title) AGAINST ('$q') ORDER BY relevance DESC LIMIT 15