Create filter to return only one site on Multisite Search tab

Last updated on
30 April 2025

You are browsing documentation for an older version of Drupal, which is not supported any longer, and the information may not be correct. See current documentation for Contributed modules

This module is dependent on the apachesolr_multisitesearch module.

Problem:
Had an apache solr index that contained multiple site indexes. On various sites contained in this index we needed results from one and only one site contained in this index. Also, needed the to rename the default tab.

Resolution:
Create a small module that adds a new hash filter for multisitesearch.

First get the site's hash. To do this utilize drush:

  1. Go to directory (or use drush alias) for site you are wanting to show up.
  2. Run: # drush vget apachesolr_site_hash
  3. Make a note of the returned has code.
  4. Sample code for filter:

    /**
     * Implementation of hook_apachesolr_modify_query().
     */
    function apachesolr_filtermultisitesearch_apachesolr_modify_query(&$query, &$params, $caller) {
      if ($caller == "apachesolr_multisitesearch") {
        // Limit to specific site search via the site hash.
        $query->add_filter('hash', 'code_retrieved_from_drush_vget');
      }
    }
    

    Sample code to rename tab:

    /**
     * Implementation of hook_search()
     */
    function apachesolr_mymodule_search($op = 'search', $keys = NULL) {
      switch ($op) {
        case 'name':
          return t('Custom Results');
      }
    }
    
    /**
     * Implementation of hook_menu_alter
     **/
    function apachesolr_mymodule_menu_alter(&$menu) {
        $menu['search/apachesolr_multisitesearch/%menu_tail']['title arguments'][0] = 'apachesolr_mymodule';
        unset($menu['search/apachesolr_mymodule/%menu_tail']);
    }
    

    I hope this helps someone else who needs this information in the future.

Help improve this page

Page status: Not set

You can: