You are here

function apachesolr_search_block in Apache Solr Search 6

Same name and namespace in other branches
  1. 5.2 apachesolr_search.module \apachesolr_search_block()
  2. 5 apachesolr_search.module \apachesolr_search_block()
  3. 6.3 apachesolr_search.module \apachesolr_search_block()
  4. 6.2 apachesolr_search.module \apachesolr_search_block()

Implementation of hook_block().

File

./apachesolr_search.module, line 559
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;
        }

        // 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);
                  return apachesolr_facet_block($response, $query, 'apachesolr_search', $delta, $index_key, t('Filter by @field', array(
                    '@field' => $field['label'],
                  )));
                }
              }
            }
        }
        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;
  }
}