我正在尝试订购我的分页结果。但它没有用。
$this->paginate = array(
'limit' => 15,
'fields' => array('*', "MATCH (headline, author, short_headline, subline, teaser, text) AGAINST ('$var') AS score"),
'conditions' => "MATCH(headline, author, short_headline, subline, teaser, text) AGAINST('$var' IN BOOLEAN MODE)",
'order' => array('score' => 'desc')
);
查询如下:
SELECT *, MATCH (`headline`, `author`, `short_headline`, `subline`, `teaser`, `text`) AGAINST ('herz tod') AS `score`, `Story`.`id` FROM `fates`.`stories` AS `Story` WHERE MATCH(headline, author, short_headline, subline, teaser, text) AGAINST('herz tod' IN BOOLEAN MODE) LIMIT 15
按分数排序消失了!我做错了什么?谢谢你的帮助!
答案 0 :(得分:1)
在尝试分页之前尝试将分数设为虚拟字段,以便使用它来分页。 (可能还有其他方法可以通过分数来订购,但我不知道它们。)
$this->Model->virtualFields['score'] = "MATCH (headline, author, short_headline, subline, teaser, text) AGAINST ('" . Sanitize::escape($var) . "')";
我还想指出,如果您不能假设$var
是值得信赖的数据,那么您的代码(以及我上面发布的代码)很容易受到SQL注入攻击,就像$var
来自用户输入一样。