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?

1 Answer 1

3

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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