按全文匹配最多匹配

时间:2013-07-27 12:25:43

标签: php mysql

我使用以下查询来搜索表中的记录:

SELECT * FROM posts WHERE MATCH (title) AGAINST ('$q')   LIMIT 15

它返回前15个结果,如何按最大匹配数量的顺序对其进行排序?

2 个答案:

答案 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