Create filter to return only one site on Multisite Search tab
Last updated on
30 April 2025
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:
- Go to directory (or use drush alias) for site you are wanting to show up.
- Run: # drush vget apachesolr_site_hash
- Make a note of the returned has code.
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:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion