php mysql全文搜索顺序相关

时间:2011-08-29 06:56:09

标签: mysql full-text-search relevance

如何按相关性制作php全文搜索顺序?

SELECT * FROM table
WHERE MATCH (col1,col2,col3) 
AGAINST ('+$boolean' IN BOOLEAN MODE)
Order By relevance

我想设置相关性,首先应该匹配col1, col2然后匹配col3,如果col1, col2完成匹配,请输入更多字词,然后输入col3

也许我应该设置一个百分比,例如col1, col2具有66%的相关性,col3具有34%的相关性......

1 个答案:

答案 0 :(得分:1)

您可以尝试这样的事情:

SELECT *, (MATCH(col1, col2) AGAINST('+$boolean' IN BOOLEAN MODE) * 0.66 + MATCH(col3) AGAINST('+$boolean' IN BOOLEAN MODE) * 0.34) AS relevance
FROM table
WHERE MATCH(col1, col2, col3) AGAINST ('+$boolean' IN BOOLEAN MODE)
ORDER BY relevance DESC