apachesolr_modify_query

Versions
5 – 6
apachesolr_modify_query(&$query, &$params, $caller)

This hook allows modules to modify the query and params objects.

Example:

function my_module_apachesolr_modify_query(&$query, &$params, $caller) { // I only want to see articles by the admin! $query->add_filter("uid", 1);

}

▾ 2 functions call apachesolr_modify_query()

apachesolr_do_query in contributions/apachesolr/apachesolr.module
Execute a search based on a query object.
apachesolr_mlt_suggestions in contributions/apachesolr/apachesolr.module
Performs a moreLikeThis query using the settings and retrieves documents.

Code

contributions/apachesolr/apachesolr.module, line 1107

<?php
function apachesolr_modify_query(&$query, &$params, $caller) {
  if (empty($query)) {
    // This should only happen if Solr is not set up - avoids fatal errors.
    return;
  }

  // Call the hooks first because otherwise any modifications to the
  // $query object don't end up in the $params.
  foreach (module_implements('apachesolr_modify_query') as $module) {
    $function_name = $module . '_apachesolr_modify_query';
    $function_name($query, $params, $caller);
  }

  // TODO: The query object should hold all the params.
  // Add array of fq parameters.
  if ($query && ($fq = $query->get_fq())) {
    $params['fq'] = $fq;
  }
  // Add sort if present.
  if ($query) {
    $sort = $query->get_solrsort();
    $sortstring = $sort['#name'] .' '. $sort['#direction'];
    // We don't bother telling Solr to do its default sort.
    if ($sortstring != 'score asc') {
      $params['sort'] = $sortstring;
    }
  }
}
?>

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters (without spaces) shown in the image.