簡體   English   中英

cakephp匹配訂單不起作用

[英]cakephp match against order by doesn't work

我正在嘗試訂購我的分頁結果。 但它不起作用。

$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

按分數排序消失了! 我做錯了什么? 感謝幫助!

在嘗試分頁之前嘗試將分數設為虛擬字段,以便使用它來分頁。 (可能還有其他方法可以按分數排序,但我不知道它們。)

$this->Model->virtualFields['score'] = "MATCH (headline, author, short_headline, subline, teaser, text) AGAINST ('" . Sanitize::escape($var) . "')";

我還想指出,以防萬一,你的代碼(以及我上面發布的代碼)容易受到SQL注入的影響,如果你不能假設$var是值得信賴的數據,比如$var來自用戶輸入。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM