function apachesolr_facet_block in Apache Solr Search 5.2
Same name and namespace in other branches
- 5 apachesolr.module \apachesolr_facet_block()
- 6 apachesolr.module \apachesolr_facet_block()
- 6.2 apachesolr.module \apachesolr_facet_block()
Helper function for displaying a facet block.
2 calls to apachesolr_facet_block()
- apachesolr_og_block in contrib/
apachesolr_og/ apachesolr_og.module - Implementation of hook_block().
- apachesolr_search_block in ./
apachesolr_search.module - Implementation of hook_block().
File
- ./
apachesolr.module, line 754 - Integration with the Apache Solr search application.
Code
function apachesolr_facet_block($response, $query, $module, $delta, $facet_field, $filter_by, $facet_callback = FALSE) {
if (!empty($response->facet_counts->facet_fields->{$facet_field})) {
$contains_active = FALSE;
$items = array();
foreach ($response->facet_counts->facet_fields->{$facet_field} as $facet => $count) {
$sortpre = 1000000 - $count;
$options = array(
'delta' => $delta,
);
$exclude = FALSE;
// Solr sends this back if it's empty.
if ($facet == '_empty_') {
$exclude = TRUE;
$facet = '[* TO *]';
$facet_text = theme('placeholder', t('Missing this field'));
$options['html'] = TRUE;
// Put this just below any active facets.
// '-' sorts before all numbers, but after '*'.
$sortpre = '-';
}
else {
$facet_text = $facet;
}
if ($facet_callback && function_exists($facet_callback)) {
$facet_text = $facet_callback($facet, $options);
}
$unclick_link = '';
$active = FALSE;
$new_query = clone $query;
if ($query
->has_filter($facet_field, $facet)) {
$contains_active = $active = TRUE;
// '*' sorts before all numbers.
$sortpre = '*';
$new_query
->remove_filter($facet_field, $facet);
$options['query'] = $new_query
->get_url_queryvalues();
$link = theme('apachesolr_unclick_link', $facet_text, $new_query
->get_path(), $options);
}
else {
$new_query
->add_filter($facet_field, $facet, $exclude);
$options['query'] = $new_query
->get_url_queryvalues();
$link = theme('apachesolr_facet_link', $facet_text, $new_query
->get_path(), $options, $count, FALSE, $response->response->numFound);
}
if ($count || $active) {
$items[$sortpre . '*' . $facet_text] = $link;
}
}
// Unless a facet is active only display 2 or more.
if ($items && ($response->response->numFound > 1 || $contains_active)) {
ksort($items, SORT_STRING);
// Get information needed by the rest of the blocks about limits.
$initial_limits = variable_get('apachesolr_facet_query_initial_limits', array());
$limit = isset($initial_limits[$module][$delta]) ? $initial_limits[$module][$delta] : variable_get('apachesolr_facet_query_initial_limit_default', 10);
$output = theme('apachesolr_facet_list', $items, $limit);
return array(
'subject' => $filter_by,
'content' => $output,
);
}
}
return NULL;
}