function apachesolr_multisitesearch_enabled_facets_form in Apache Solr Multisite Search 6
Same name and namespace in other branches
- 6.2 apachesolr_multisitesearch.admin.inc \apachesolr_multisitesearch_enabled_facets_form()
Creates the form that allows the user to select which facets will be enabled.
Only enabled facets are sent to solr. Fewer enabled facets can reduce the load on the search server. Blocks are only offered for enabled facets, so this also reduces the clutter on the blocks admin page.
1 string reference to 'apachesolr_multisitesearch_enabled_facets_form'
- apachesolr_multisitesearch_menu in ./
apachesolr_multisitesearch.module - Implementation of hook_menu().
File
- ./
apachesolr_multisitesearch.admin.inc, line 131 - Provides a multi-site search admin pages and functionality
Code
function apachesolr_multisitesearch_enabled_facets_form() {
$form = array();
$facets = array();
$module_facets = array();
$module_list = array();
foreach (module_implements('apachesolr_multisitesearch_facets') as $module) {
$module_facets[$module] = module_invoke($module, 'apachesolr_multisitesearch_facets', TRUE);
uasort($module_facets[$module], '_apachesolr_multisitesearch_sort_facets');
$module_list[$module] = $module;
}
$enabled_facets = apachesolr_multisitesearch_enabled_facets();
$form = array();
$form['apachesolr_multisitesearch_enabled_facets']['help'] = array(
'#type' => 'item',
'#value' => t('You can use this screen to select which search filter blocks should be created by enabling the corresponding filters on this page. For performance reasons, you should only enable filters that you intend to have available to users on the search page. After selecting which filter blocks to create, you will be sent to the blocks page where you can choose which of those blocks should be enabled when your users search by placing each block in a region.'),
);
if ($module_list) {
$placeholders = implode(', ', array_fill(0, count($module_list), "'%s'"));
$result = db_query("SELECT name, info FROM {system} WHERE name IN (" . $placeholders . ") AND type = 'module'", $module_list);
while ($item = db_fetch_array($result)) {
$module_list[$item['name']] = unserialize($item['info']);
}
}
foreach ($module_facets as $module => $facets) {
$form['apachesolr_multisitesearch_enabled_facets'][$module] = array(
'#type' => 'fieldset',
'#title' => check_plain($module_list[$module]['name']),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
// We must use module + delta as the keys since that combination is
// guaranteed to be unique. A single module could, for example, have
// two different blocks that expose different faceting on the same
// field in the index.
foreach ($facets as $delta => $data) {
$form['apachesolr_multisitesearch_enabled_facets'][$module][$delta] = array(
'#type' => 'checkbox',
'#title' => $data['info'],
'#return_value' => $data['facet_field'],
'#default_value' => isset($enabled_facets[$module][$delta]) ? $data['facet_field'] : 0,
);
}
}
$has_facets = (bool) $module_facets;
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#access' => $has_facets,
);
$form['no-facets-message'] = array(
'#value' => t('<em>No filters are available from your currently enabled modules</em>'),
'#access' => !$has_facets,
);
$form['#tree'] = TRUE;
$form['submit_message'] = array(
'#type' => 'value',
'#value' => t('The Apache Solr Multisite Search filter settings were changed. To arrange the blocks for your enabled filters, visit the <a href="@url">blocks administration page</a>.', array(
'@url' => url('admin/build/block'),
)),
);
$form['admin'] = array(
'#type' => 'fieldset',
'#title' => t('Administrative functions'),
);
$form['admin']['refresh'] = array(
'#type' => 'submit',
'#value' => t('Refresh metadata now'),
'#prefix' => '<p>' . t('Multisite metadata is used to communicate between all of the sites in a multisite setup. If site names are not showing properly in the search results and facet blocks try refreshing the metadata. Metadata is also refreshed periodically on cron runs.') . '</p>',
'#submit' => array(
'apachesolr_multisitesearch_refresh_metadata_now',
),
);
// Use the metadata and a list of all the hashes in the index
// to build up checkboxes for deleting site indexes.
// This is only necessary because sometimes hashes get
// stranded in the index and deleting the index from the normal
// admin screen doesn't rectify the problem.
$metadata = variable_get('apachesolr_multisitesearch_metadata', array());
$hashes = apachesolr_multisitesearch_get_site_hashes();
foreach ($hashes as $hash => $count) {
if ($hash == apachesolr_site_hash()) {
$options[$hash] = t('This site (!site, !count documents)', array(
'!site' => variable_get('site_name', 'Drupal'),
'!count' => $count,
));
}
elseif (!empty($metadata[$hash])) {
$options[$hash] = $metadata[$hash]['site'] . ' ' . t('(!count documents)', array(
'!count' => $count,
));
}
else {
$options[$hash] = $hash . ' ' . t('(!count documents)', array(
'!count' => $count,
));
}
}
if (count($options) > 0) {
$form['admin']['delete']['hashes'] = array(
'#type' => 'checkboxes',
'#title' => t('Delete data from sites using this index'),
'#options' => $options,
'#description' => t('If you end up in a situation where the index has hashes that no longer map to real active sites, use this option to delete the outdated data. If you delete another site\'s index from this site, that site will have to first trigger a re-index, and then run cron until the index is rebuilt.'),
);
$form['admin']['delete']['submit'] = array(
'#type' => 'submit',
'#value' => t('Delete selected indexes'),
'#submit' => array(
'apachesolr_multisitesearch_delete_indexes',
),
);
}
return $form;
}