You are here

function hook_search_api_db_query_alter in Search API Database Search 7

Preprocesses a search's database query before it is executed.

Parameters

SelectQueryInterface $db_query: The database query to be executed for the search. Will have "item_id" and "score" columns in its result.

SearchApiQueryInterface $query: The search query that is being executed.

See also

SearchApiDbService::preQuery()

1 invocation of hook_search_api_db_query_alter()
SearchApiDbService::createDbQuery in ./service.inc
Creates a database query for a search.

File

./search_api_db.api.php, line 24
Hooks provided by the Database Search module.

Code

function hook_search_api_db_query_alter(SelectQueryInterface &$db_query, SearchApiQueryInterface $query) {

  // If the option was set on the query, add additional SQL conditions.
  if ($custom = $query
    ->getOption('custom_sql_conditions')) {
    foreach ($custom as $condition) {
      $db_query
        ->condition($condition['field'], $condition['value'], $condition['operator']);
    }
  }
}