You are here

function apachesolr_multisitesearch_execute in Apache Solr Multisite Search 6

Same name and namespace in other branches
  1. 6.2 apachesolr_multisitesearch.module \apachesolr_multisitesearch_execute()

Execute a search results based on keyword, filter, and sort strings.

Throws

Exception

1 call to apachesolr_multisitesearch_execute()
apachesolr_multisitesearch_search in ./apachesolr_multisitesearch.module
Implementation of hook_search()

File

./apachesolr_multisitesearch.module, line 106
Provides a multi-site search implementation for use with the Apache Solr module

Code

function apachesolr_multisitesearch_execute($keys, $filters, $solrsort, $base_path = '', $page = 0, $caller = 'apachesolr_multisitesearch') {
  $params = array();

  // This is the object that knows about the query coming from the user.
  $query = apachesolr_drupal_query($keys, $filters, $solrsort, $base_path);
  if (empty($query)) {
    throw new Exception(t('Could not construct a Solr query in function apachesolr_search_search()'));
  }
  $query->multisite = TRUE;

  // This is the object that does the communication with the solr server.
  $solr = apachesolr_get_solr();
  $params += apachesolr_multisitesearch_basic_params($query);
  if ($keys) {
    $params += apachesolr_search_highlighting_params($query);
    $params += apachesolr_search_spellcheck_params($query);
  }
  else {

    // No highlighting, use the teaser as a snippet.
    $params['fl'] .= ',teaser';
  }
  apachesolr_multisitesearch_add_facet_params($params, $query);
  apachesolr_search_add_boost_params($params, $query, $solr);

  // Allow modules to alter the query prior to statically caching it.
  // This can e.g. be used to add available sorts.
  foreach (module_implements('apachesolr_prepare_query') as $module) {
    $function_name = $module . '_apachesolr_prepare_query';
    $function_name($query, $params, $caller);
  }

  // Cache the built query. Since all the built queries go through
  // this process, all the hook_invocations will happen later
  $current_query = apachesolr_current_query($query);

  // This hook allows modules to modify the query and params objects.
  apachesolr_modify_query($query, $params, $caller);
  $params['start'] = $page * $params['rows'];
  if (!$query) {
    return array();
  }
  if ('' == $keys && isset($params['fq'])) {

    // Move the fq params to the q.alt for better performance.
    $params['q.alt'] = implode(' ', $params['fq']);
    unset($params['fq']);
  }

  // We must run htmlspecialchars() here since converted entities are in the index.
  // and thus bare entities &, > or < won't match.
  $response = $solr
    ->search(htmlspecialchars($query
    ->get_query_basic(), ENT_NOQUOTES, 'UTF-8'), $params['start'], $params['rows'], $params);

  // The response is cached so that it is accessible to the blocks and anything
  // else that needs it beyond the initial search.
  apachesolr_static_response_cache($response);
  apachesolr_multisitesearch_has_searched(TRUE);

  // Add search terms and filters onto the breadcrumb.
  drupal_set_breadcrumb(array_merge(menu_get_active_breadcrumb(), $current_query
    ->get_breadcrumb()));
  return apachesolr_multisitesearch_process_response($response, $query, $params);
}