使用“AS得分”从mysql全文搜索返回相关性得分

时间:2012-05-06 18:55:09

标签: php mysql full-text-search relevance

我正在从全文mysql dbTable中选择文本,命中按相关性排序,再乘以客户端提供的权重。查询工作正常,但我想作为一个 查询的“AS score”子句将实际加权相关性分数返回给客户端(通过php)。我试过到处插入AS子句,但没有成功。 建议? 谢谢

$sql1="SELECT * FROM $dbTable 
WHERE MATCH (data) AGAINST ('".$key_word_1."') 
   OR MATCH (data) AGAINST('".$key_word_2."') 
ORDER BY (MATCH (data) AGAINST('".$key_word_1."') * $weight_1) + (MATCH (data) AGAINST('".$key_word_2."') * $weight_2)  DESC 
LIMIT 200";

1 个答案:

答案 0 :(得分:1)

你可以这样做:

SELECT * , (MATCH (data) AGAINST('".$key_word_1."') * $weight_1) + (MATCH (data) AGAINST('".$key_word_2."') * $weight_2) AS score
....
ORDER BY score DESC