You are here

function apachesolr_search_view in Apache Solr Search 5.2

Same name and namespace in other branches
  1. 6 apachesolr_search.module \apachesolr_search_view()
  2. 6.2 apachesolr_search.module \apachesolr_search_view()

Re-implementation of search_view().

File

./apachesolr_search.module, line 118
Provides a content search implementation for node content for use with the Apache Solr search application.

Code

function apachesolr_search_view($type = NULL) {

  // Search form submits with POST but redirects to GET.
  $results = '';
  if (!isset($_POST['form_id'])) {
    if (empty($type)) {

      // Note: search/X can not be a default tab because it would take on the
      // path of its parent (search). It would prevent remembering keywords when
      // switching tabs. This is why we drupal_goto to it from the parent instead.
      drupal_goto('search/apachesolr_search');
    }
    $keys = trim(search_get_keys());
    $filters = '';
    if (isset($_GET['filters'])) {
      $filters = trim($_GET['filters']);
    }

    // Only perform search if there is non-whitespace search term or filters:
    if ($keys || $filters) {

      // Log the search keys:
      $log = $keys;
      if ($filters) {
        $log .= 'filters=' . $filters;
      }
      watchdog('search', t('!log (!search)', array(
        '!log' => $log,
        '!search' => 'Search',
      )), WATCHDOG_NOTICE, l(t('results'), 'search/' . $type . '/' . $keys));

      // Collect the search results:
      $results = search_data($keys, $type);
      if ($results) {
        $results = theme('box', t('Search results'), $results);
      }
      else {
        $results = theme('box', t('Your search yielded no results'), variable_get('apachesolr_search_noresults', apachesolr_search_noresults()));
      }
    }
  }

  // Construct the search form.
  return drupal_get_form('search_form', NULL, $keys, $type) . $results;
}