function apachesolr_search_block in Apache Solr Search 6.2
Same name and namespace in other branches
- 5.2 apachesolr_search.module \apachesolr_search_block()
- 5 apachesolr_search.module \apachesolr_search_block()
- 6.3 apachesolr_search.module \apachesolr_search_block()
- 6 apachesolr_search.module \apachesolr_search_block()
Implementation of hook_block().
File
- ./
apachesolr_search.module, line 770 - Provides a content search implementation for node content for use with the Apache Solr search application.
Code
function apachesolr_search_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$enabled_facets = apachesolr_get_enabled_facets('apachesolr_search');
$facets = apachesolr_search_apachesolr_facets();
// Add the blocks
$blocks = array();
foreach ($enabled_facets as $delta => $facet_field) {
if (isset($facets[$delta])) {
$blocks[$delta] = $facets[$delta] + array(
'cache' => BLOCK_CACHE_PER_ROLE | BLOCK_CACHE_PER_PAGE,
);
}
}
$blocks['currentsearch'] = array(
'info' => t('Apache Solr Search: Current search'),
'cache' => BLOCK_CACHE_PER_PAGE,
);
return $blocks;
case 'view':
if (apachesolr_has_searched()) {
// Get the query and response. Without these no blocks make sense.
$response = apachesolr_static_response_cache();
if (empty($response)) {
return;
}
$query = apachesolr_current_query();
$facets = apachesolr_get_enabled_facets('apachesolr_search');
if (empty($facets[$delta]) && $delta != 'currentsearch') {
return;
}
if (!apachesolr_block_visibility($query, 'apachesolr_search', $delta)) {
return;
}
// Handle taxonomy vocabulary facets
if (strpos($delta, 'im_vid_') === 0) {
return apachesolr_search_taxonomy_facet_block($response, $query, $delta);
}
switch ($delta) {
case 'currentsearch':
return apachesolr_search_currentsearch_block($response, $query);
case 'is_book_bid':
return apachesolr_facet_block($response, $query, 'apachesolr_search', $delta, $delta, t('Filter by book'), 'apachesolr_search_get_book');
case 'language':
return apachesolr_facet_block($response, $query, 'apachesolr_search', $delta, $delta, t('Filter by language'), 'apachesolr_search_language_name');
case 'uid':
return apachesolr_facet_block($response, $query, 'apachesolr_search', $delta, $delta, t('Filter by author'), 'apachesolr_search_get_username');
case 'type':
return apachesolr_facet_block($response, $query, 'apachesolr_search', $delta, $delta, t('Filter by type'), 'apachesolr_search_get_type');
case 'changed':
return apachesolr_date_facet_block($response, $query, 'apachesolr_search', $delta, $delta, t('Filter by modification date'));
case 'created':
return apachesolr_date_facet_block($response, $query, 'apachesolr_search', $delta, $delta, t('Filter by post date'));
default:
if ($fields = apachesolr_cck_fields()) {
foreach ($fields as $name => $field) {
if ($field['field_name'] == $delta) {
$index_key = apachesolr_index_key($field);
$callback = isset($field['display_callback']) ? $field['display_callback'] : FALSE;
$block_function = isset($field['facet_block_callback']) && function_exists($field['facet_block_callback']) ? $field['facet_block_callback'] : 'apachesolr_facet_block';
return $block_function($response, $query, 'apachesolr_search', $delta, $index_key, t('Filter by @field', array(
'@field' => $field['widget']['label'],
)), $callback);
}
}
}
}
break;
}
break;
case 'configure':
if ($delta != 'currentsearch') {
return apachesolr_facetcount_form('apachesolr_search', $delta);
}
break;
case 'save':
if ($delta != 'currentsearch') {
apachesolr_facetcount_save($edit);
}
break;
}
}