function hook_search_api_db_query_alter in Search API 8
Preprocess a search's database query before it is executed.
This allows other modules to alter the DB query before a count query (or facet queries, or other related queries) are constructed from it.
Parameters
\Drupal\Core\Database\Query\SelectInterface $db_query: The database query to be executed for the search. Will have "item_id" and "score" columns in its result.
\Drupal\search_api\Query\QueryInterface $query: The search query that is being executed.
Deprecated
in search_api:8.x-1.16 and is removed from search_api:2.0.0. Please use the "search_api_db.query_pre_execute" event instead.
See also
https://www.drupal.org/node/3103591
\Drupal\search_api_db\Plugin\search_api\backend\Database::preQuery()
1 function implements hook_search_api_db_query_alter()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- search_api_test_db_search_api_db_query_alter in tests/
search_api_test_db/ search_api_test_db.search_api.inc - Implements hook_search_api_db_query_alter().
File
- modules/
search_api_db/ search_api_db.api.php, line 31 - Hooks provided by the Database Search module.
Code
function hook_search_api_db_query_alter(\Drupal\Core\Database\Query\SelectInterface &$db_query, \Drupal\search_api\Query\QueryInterface $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']);
}
}
}