function apachesolr_facet_block in Apache Solr Search 5
Same name and namespace in other branches
- 5.2 apachesolr.module \apachesolr_facet_block()
- 6 apachesolr.module \apachesolr_facet_block()
- 6.2 apachesolr.module \apachesolr_facet_block()
3 calls to apachesolr_facet_block()
- apachesolr_block in ./
apachesolr.module - Implementation of hook_block().
- apachesolr_multisitesearch_block in contrib/
apachesolr_multisitesearch/ apachesolr_multisitesearch.module - Implementation of hook_block().
- apachesolr_search_block in ./
apachesolr_search.module - Implementation of hook_block().
File
- ./
apachesolr.module, line 566 - Integration with the Apache Solr search application.
Code
function apachesolr_facet_block($response, $query, $delta, $filter_by, $facet_callback = FALSE) {
if (!empty($response->facet_counts->facet_fields->{$delta})) {
$contains_active = FALSE;
$items = array();
foreach ($response->facet_counts->facet_fields->{$delta} as $facet => $count) {
$unclick_link = '';
unset($active);
if ($facet_callback && function_exists($facet_callback)) {
$facet_text = $facet_callback($facet);
}
else {
$facet_text = $facet;
}
$new_query = clone $query;
if ($active = $query
->has_field($delta, $facet)) {
$contains_active = TRUE;
$new_query
->remove_field($delta, $facet);
$path = 'search/' . arg(1) . '/' . $new_query
->get_query();
$unclick_link = theme('apachesolr_unclick_link', $path);
}
else {
$new_query
->add_field($delta, $facet);
$path = 'search/' . arg(1) . '/' . $new_query
->get_query();
}
$countsort = $count == 0 ? '' : 1 / $count;
// if numdocs == 1 and !active, don't add.
if ($response->numFound == 1 && !$active) {
// skip
}
else {
$items[$active ? $countsort . $facet : 1 + $countsort . $facet] = theme('apachesolr_facet_item', $facet_text, $count, $path, $active, $unclick_link, $response->numFound);
}
}
if (count($items) > 0) {
ksort($items);
$facet_display_limit = isset($facet_display_limits[$delta]) ? $facet_display_limits[$delta] : 10;
$items = array_slice($items, 0, $facet_display_limit == -1 ? NULL : $facet_display_limit);
$output = theme('apachesolr_facet_list', $items);
return array(
'subject' => t('@filter_by', array(
'@filter_by' => $filter_by,
)),
'content' => $output,
);
}
}
return NULL;
}