如何按相关性制作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%的相关性......
答案 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