You are here

function hook_search_api_solr_converted_query_alter in Search API Solr 8.2

Same name and namespace in other branches
  1. 8.3 search_api_solr.api.php \hook_search_api_solr_converted_query_alter()
  2. 4.x search_api_solr.api.php \hook_search_api_solr_converted_query_alter()

Lets modules alter the converted Solarium select query before executing it.

This hook is called after the select query is finally converted into an expression that meets the requirements of the trageted query parser. Using this hook you can carefully modify the 'q' parameter here, in oposite to hook_search_api_solr_query_alter().

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_converted_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 121
Hooks provided by the Search API Solr search module.

Code

function hook_search_api_solr_converted_query_alter(\Solarium\Core\Query\QueryInterface $solarium_query, \Drupal\search_api\Query\QueryInterface $query) {
  if ($query
    ->getOption('I_know_what_I_am_doing') == 'really!') {

    // If the Search API query has a 'I_know_what_I_am_doing' option set to
    // 'really!', overwrite the 'q' parameter.
    // query handler and add some boost queries.

    /** @var array $solr_field_names
             maps search_api field names to real field names in the Solr index
        */
    $solr_field_names = $query
      ->getIndex()
      ->getServerInstance()
      ->getBackend()
      ->getSolrFieldNames($query
      ->getIndex());

    /** @var \Solarium\Component\EdisMax $edismax */
    $edismax = $solarium_query
      ->setQuery($solr_field_names['title'] . ':' . $solarium_query
      ->getHelper()
      ->escapePhrase('foo') . '^11.0');
  }
}