我正在使用像这样的查询:
SELECT p.name, d.overview
FROM products AS p
LEFT JOIN descriptions AS d ON p.DescriptionID = d.ID
WHERE MATCH (p.name) AGAINST ('ram' IN BOOLEAN MODE) > 0
OR MATCH (d.overview) AGAINST ('ram' IN BOOLEAN MODE) > 0;
如何对此结果进行相关排序?
我试过
ORDER BY MATCH (p.name) AGAINST ('ram' IN BOOLEAN MODE)
OR MATCH (d.overview) AGAINST ('ram' IN BOOLEAN MODE) DESC
但是这并没有帮助因为结果不是根据它们的相关性进行排序。
答案 0 :(得分:1)
MATCH ... OR MATCH ...
^^
or
使其成为二进制表达式。二进制表达式的计算结果为true或false。所以你要根据它们是否匹配进行排序。因为where
子句已经确保所有行都匹配,所以这不是添加排序。
尝试按整数表达式排序,例如总和相关性:
ORDER BY
MATCH (p.name) AGAINST ('ram' IN BOOLEAN MODE) +
MATCH (d.overview) AGAINST ('ram' IN BOOLEAN MODE) DESC