function _ds_search_group_by_type_multisearch in Display Suite 7.2
Helper function to perform grouping on Apache Solr multisearch.
1 call to _ds_search_group_by_type_multisearch()
- ds_search_search_page in modules/
ds_search/ ds_search.module - Implements hook_search_page().
File
- modules/
ds_search/ ds_search.module, line 392 - Display Suite search.
Code
function _ds_search_group_by_type_multisearch(&$build) {
$site_counter = array();
$conf_array = array();
$config = explode("\n", variable_get('ds_search_apachesolr_multisite_group_config'));
foreach ($config as $weight => $conf) {
$conf = trim($conf);
if (empty($conf)) {
continue;
}
$site_conf = explode('|', $conf);
$conf_array[$site_conf[0]] = array(
'label' => $site_conf[1],
'wrapper' => $site_conf[2],
'weight' => $weight,
);
}
// Iterate over results.
foreach ($build['search_results'] as $id => $result) {
if (!isset($build['search_results'][$result['#site_hash']])) {
$class = 'group-result group-result-' . strtr($result['#site_hash'], '_', '-');
$build['search_results'][$result['#site_hash']] = array(
'#type' => 'fieldset',
'#weight' => $conf_array[$result['#site_hash']]['weight'],
'#attributes' => array(
'class' => array(
$class,
),
),
);
// Create site counter.
$site_counter[$result['#site_hash']] = array(
'counter' => 0,
'title' => $conf_array[$result['#site_hash']]['label'],
'type' => $conf_array[$result['#site_hash']]['wrapper'],
'class' => $class,
);
}
// Move result into other wrapper and unset previous. Also count for
// every site so we can populate @total_per_site later on.
$site_counter[$result['#site_hash']]['counter']++;
$build['search_results'][$result['#site_hash']][$id] = $result;
unset($build['search_results'][$id]);
}
// Site counter.
foreach ($site_counter as $hash => $values) {
$title = check_plain(t($values['title'], array(
'!total_per_site' => format_plural($values['counter'], '1 result', '@count results'),
)));
if ($values['type'] == 'div') {
$build['search_results'][$hash]['#prefix'] = '<div class="' . $values['class'] . '">' . (!empty($title) ? '<h2>' . $title . '</h2>' : '');
$build['search_results'][$hash]['#suffix'] = '</div>';
}
else {
$build['search_results'][$hash]['#title'] = $title;
}
}
}