You are here

function apachesolr_multisitesearch_apachesolr_query_alter in Apache Solr Multisite Search 6.3

Same name and namespace in other branches
  1. 7 apachesolr_multisitesearch.module \apachesolr_multisitesearch_apachesolr_query_alter()

Implements hook_apachesolr_query_alter().

Verifies if the environment is multisite enabled, and if so, returns results from the while index. Otherwise it only returns results from the current site.

Parameters

DrupalSolrQueryInterface $query:

File

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

Code

function apachesolr_multisitesearch_apachesolr_query_alter(DrupalSolrQueryInterface $query) {
  if (empty($query->multisite)) {
    $env_id = $query
      ->solr('getId');
    $multisite = apachesolr_environment_variable_get($env_id, 'multisitesearch');

    // Add hash and site to our fields to retrieve
    $query
      ->addParam('fl', 'hash');
    $query
      ->addParam('fl', 'site');
    if (empty($multisite)) {

      // Limit single site searchs via the site hash.
      $query
        ->addFilter('hash', apachesolr_site_hash());
    }
  }

  // Get the variable which contains the query exclusion keys.
  $excluded_bundles = variable_get('apachesolr_multisitesearch_query_exclusions', array());
  if (isset($excluded_bundles) && !empty($excluded_bundles)) {

    // Get all of the bundle names which can be excluded.
    $query_exclusion_options = apachesolr_multisitesearch_query_bundles();

    // Map the excluded bundle keys to their values and bundle names.
    foreach ($excluded_bundles as $key) {
      $excluded_bundles[$key] = $query_exclusion_options[$key];
    }

    // Create filters for the flagged keys and exclude them from search.
    foreach ($excluded_bundles as $filtered_content) {
      $query
        ->addFilter('bundle_name', $filtered_content, TRUE);
    }
  }
}