function apachesolr_multisitesearch_apachesolr_query_alter in Apache Solr Multisite Search 7
Same name and namespace in other branches
- 6.3 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 251 - 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)) {
// Add hash and site to our fields to retrieve
$query
->addParam('fl', 'hash');
$query
->addParam('fl', 'site');
// Restrict the query to certain sites.
if ($subquery = apachesolr_multisitesearch_build_site_subquery($query
->solr('getId'))) {
$query
->addFilterSubQuery($subquery);
}
}
// 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) {
if (isset($query_exclusion_options[$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);
}
}
}