1

I have a query like:

$query = db_query("
    SELECT *, MATCH(field1,field2) AGAINST ('$s' IN BOOLEAN MODE) AS Relevance 
    FROM {my_table} 
    ORDER BY Relevance DESC, created DESC
    ");

That is working well with db_query.
How can i use same query with db_select function for drupal 7?

2

Adding an expression should work:

 $query = db_select('foo');
 ...
 $expression = 'MATCH(field1,field2) AGAINST (:search IN BOOLEAN MODE)';
 $query->addExpression($expression, 'Relevance', [':search' => '$s']);
 ...

See SelectQuery::addExpression for more info.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.