hook_apachesolr_query_alter

  1. apachesolr
    1. 7
Versions
7 hook_apachesolr_query_alter($query)

Alter the query after it's prepared and cached.

Any module performing a search should call drupal_alter('apachesolr_query', $query). That function then invokes this hook. It allows modules to modify the query object and its parameters.

A module implementing HOOK_apachesolr_query_alter() may set $query->abort_search to TRUE to flag the query to be aborted.

Parameters

$query An object implementing DrupalSolrQueryInterface. No need for &.

Code

./apachesolr.api.php, line 40

<?php
function hook_apachesolr_query_alter($query) {
  // I only want to see articles by the admin!
  $query->addFilter("is_uid", 1);

  // Only search titles.
  $query->replaceParam('qf', 'label');
}
?>