diff --git a/docroot/sites/all/modules/contrib/apachesolr_multisitesearch/apachesolr_multisitesearch.admin.inc b/docroot/sites/all/modules/contrib/apachesolr_multisitesearch/apachesolr_multisitesearch.admin.inc index 1e8349e..2fe8686 100644 --- a/docroot/sites/all/modules/contrib/apachesolr_multisitesearch/apachesolr_multisitesearch.admin.inc +++ b/docroot/sites/all/modules/contrib/apachesolr_multisitesearch/apachesolr_multisitesearch.admin.inc @@ -59,10 +59,56 @@ function apachesolr_multisitesearch_settings() { '#submit' => array('apachesolr_multisitesearch_delete_indexes'), ); } + + // Grab the bundle names from the metadata and load them as options. + $query_exclusion_options = apachesolr_multisitesearch_query_bundles(); + // Grab the excluded item keys from the variables. + $excluded_bundles = variable_get('apachesolr_multisitesearch_query_exclusions', array()); + + $form['query_exclusions'] = array( + '#type' => 'fieldset', + '#title' => t('Search Result Exclusions'), + ); + $form['query_exclusions']['exclusion_options'] = array( + '#default_value' => $excluded_bundles ? $excluded_bundles : '', + '#description' => t('Content types to exclude from search. Hold CTRL to select make more than one selection.'), + '#multiple' => true, + '#options' => $query_exclusion_options, + '#prefix' => '
', + '#suffix' => '
', + '#title' => t('Content Types'), + '#type' => 'select', + ); + $form['query_exclusions']['submit'] = array( + '#type' => 'submit', + '#value' => t('Exclude content types'), + '#submit' => array('apachesolr_multisitesearch_exclude_indexes'), + ); + return $form; } /** + * Submit handler for the "Exclude content types" button. + */ +function apachesolr_multisitesearch_exclude_indexes($form, &$form_state) { + if (isset($form['query_exclusions']['exclusion_options']['#value']) && !empty($form['query_exclusions']['exclusion_options']['#value'])) { + // Set the variable to store the query filter keys and create a string to display the excluded content. + variable_set('apachesolr_multisitesearch_query_exclusions', $form['query_exclusions']['exclusion_options']['#value']); + $query_exclusion_options = apachesolr_multisitesearch_query_bundles(); + // Match the exclusion options' keys to their values and slap them together. + $matches = array_intersect_key($query_exclusion_options, $form['query_exclusions']['exclusion_options']['#value']); + $output = implode($matches, ", "); + drupal_set_message('The following content types will be excluded from search: ' . $output . '.'); + } + else { + // If nothing is selected to be excluded, delete the variable, and let the user know. + variable_del('apachesolr_multisitesearch_query_exclusions'); + drupal_set_message('No content types will be excluded from search.'); + } +} + +/** * Submit handler for the "Delete selected indexes" button. */ function apachesolr_multisitesearch_delete_indexes($form, &$form_state) { diff --git a/docroot/sites/all/modules/contrib/apachesolr_multisitesearch/apachesolr_multisitesearch.module b/docroot/sites/all/modules/contrib/apachesolr_multisitesearch/apachesolr_multisitesearch.module index 52a4c16..0a1ca1b 100644 --- a/docroot/sites/all/modules/contrib/apachesolr_multisitesearch/apachesolr_multisitesearch.module +++ b/docroot/sites/all/modules/contrib/apachesolr_multisitesearch/apachesolr_multisitesearch.module @@ -100,7 +100,7 @@ function apachesolr_multisitesearch_map_hash() { function apachesolr_multisitesearch_apachesolr_process_results(&$results, DrupalSolrQueryInterface $query) { $env_id = $query->solr('getId'); $multisite = apachesolr_environment_variable_get($env_id, 'multisitesearch'); - if (!empty($multisite)) { + if (!empty($multisite)) { foreach ($results as $id => $result) { $results[$id]['extra']['hash'] = theme('apachesolr_multisitesearch_breadcrumb_hash', array('hash' => $results[$id]['fields']['hash'])); $results[$id]['link'] = $results[$id]['fields']['url']; @@ -109,6 +109,37 @@ function apachesolr_multisitesearch_apachesolr_process_results(&$results, Drupal } /** +* Returns available bundle names. +* +* @return array +* An array listing all of the bundle names for content types. +* +* TODO: Check for duplicates in domains. We should create a domain option, +* for users to select what they want to. +*/ +function apachesolr_multisitesearch_query_bundles() { + $query_bundle_names = array(); + + // Check variables for the metadata which contains the bundles and bundle + // names. + $sites = variable_get('apachesolr_multisitesearch_metadata', array()); + if (isset($sites) && !empty($sites)) { + // Iterates for each site available in the multi-site search + foreach ($sites as $key => $value) { + // Grabs all of the bundle names and save them. + foreach ($value['sm_multisite_meta_bundles'] as $bundle_name) { + $query_bundle_names[] = $bundle_name; + } + } + // Sort the bundle names for user readability. Sorting is done here so + // mapping keys to values later happens properly. + sort($query_bundle_names); + } + $query_bundle_names = array_unique($query_bundle_names); + return($query_bundle_names); +} + +/** * Implements hook_apachesolr_query_alter(). * * Verifies if the environment is multisite enabled, and if so, returns @@ -128,6 +159,21 @@ function apachesolr_multisitesearch_apachesolr_query_alter(DrupalSolrQueryInterf $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); + } + } } /**