You are here

function hook_search_api_query_TAG_alter in Search API 8

Alter a search query with a specific tag before it gets executed.

The hook is invoked after all enabled processors have preprocessed the query.

Parameters

\Drupal\search_api\Query\QueryInterface $query: The query that will be executed.

Deprecated

in search_api:8.x-1.14 and is removed from search_api:2.0.0. Please use the "search_api.query_pre_execute.TAG" event instead.

See also

https://www.drupal.org/node/3059866

1 function implements hook_search_api_query_TAG_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_hooks_search_api_query_views_search_api_test_view_alter in tests/search_api_test_hooks/search_api_test_hooks.module
Implements hook_search_api_query_TAG_alter().

File

./search_api.api.php, line 364
Hooks provided by the Search API module.

Code

function hook_search_api_query_TAG_alter(\Drupal\search_api\Query\QueryInterface $query) {

  // Exclude the node with ID 10 from the search results.
  $fields = $query
    ->getIndex()
    ->getFields();
  foreach ($query
    ->getIndex()
    ->getDatasources() as $datasource_id => $datasource) {
    if ($datasource
      ->getEntityTypeId() == 'node') {
      if (isset($fields['nid'])) {
        $query
          ->addCondition('nid', 10, '<>');
      }
    }
  }
}