You are here

function hook_search_api_solr_query_alter in Search API Solr 8

Same name and namespace in other branches
  1. 8.3 search_api_solr.api.php \hook_search_api_solr_query_alter()
  2. 8.2 search_api_solr.api.php \hook_search_api_solr_query_alter()
  3. 7 search_api_solr.api.php \hook_search_api_solr_query_alter()
  4. 4.x search_api_solr.api.php \hook_search_api_solr_query_alter()

Lets modules alter the Solarium select query before executing it.

Parameters

\Solarium\Core\Query\QueryInterface $solarium_query: The Solarium query object, as generated from the Search API query.

\Drupal\search_api\Query\QueryInterface $query: The Search API query object representing the executed search query.

1 invocation of hook_search_api_solr_query_alter()
SearchApiSolrBackend::search in src/Plugin/search_api/backend/SearchApiSolrBackend.php
Options on $query prefixed by 'solr_param_' will be passed natively to Solr as query parameter without the prefix. For example you can set the "Minimum Should Match" parameter 'mm' to '75%' like this:

File

./search_api_solr.api.php, line 21
Hooks provided by the Search API Solr search module.

Code

function hook_search_api_solr_query_alter(\Solarium\Core\Query\QueryInterface $solarium_query, \Drupal\search_api\Query\QueryInterface $query) {
  if ($query
    ->getOption('foobar')) {

    // If the Search API query has a 'foobar' option, remove all sorting options
    // from the Solarium query.
    $solarium_query
      ->clearSorts();
  }
}