0
I’m trying to sort a query by relevance with cakephp using Paginator, but simply it ignores the alias, I already searched the manual but so far I haven’t found the solution, the query works perfectly, when I debug generates the query below, but the order by does not appear see:
SELECT *, MATCH (`titulo`,`conteudo`) AGAINST ('e-mail marketing' IN BOOLEAN MODE) AS relevance, MATCH (`titulo`) AGAINST ('e-mail marketing' IN BOOLEAN MODE) AS title_relevance FROM `db_forum`.`ra_forum` AS `Forum` WHERE MATCH (titulo,conteudo) AGAINST ('e-mail marketing' IN BOOLEAN MODE) LIMIT 10
Follows the code:
$this->paginate = array(
'fields' => array('*', "MATCH (`titulo`,`conteudo`) AGAINST ('$q' IN BOOLEAN MODE) AS relevance, MATCH (`titulo`) AGAINST ('$q' IN BOOLEAN MODE) AS title_relevance"),
'conditions' => "MATCH (`titulo`,`conteudo`) AGAINST ('$q' IN BOOLEAN MODE)",
'order' => array( 'relevance' => 'desc', 'title_relevance' => 'desc'),
'limit' => 10
);
Some trick to make it work?
Edit:
Tip for those who need, I was putting as parameters, the correct is:
'order' => 'relevance desc, title_relevance desc',
I may be wrong, but I think 'order' only accepts one parameter. You’re trying to order using two things
– Igor Martins
I found the error, no need to go through array is direct!
– Williams
Actually, it is not correct, you need to reference the model at the beginning of the array, or in each field.
– Marcelo Aymone