You are here

function apachesolr_search_view in Apache Solr Search 6

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

Re-implementation of search_view().

1 string reference to 'apachesolr_search_view'
apachesolr_search_menu_alter in ./apachesolr_search.module
Implementation of hook_menu_alter().

File

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

Code

function apachesolr_search_view($type = NULL) {
  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());

  // Construct the search form.  If the user submits POST data, this will
  // redirect to a GET request before the search actually runs.
  if (isset($_POST['form_id']) && $_POST['form_id'] == 'search_form') {
    $form = drupal_get_form('search_form', NULL, $keys, $type);
  }

  // We did not redirect, so run the search if needed.
  $results = '';
  $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', '%keys (@type).', array(
      '%keys' => $log,
      '@type' => t('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()));
    }
  }
  if (empty($form)) {

    // The form may be altered based on the query that was run.
    $form = drupal_get_form('search_form', NULL, $keys, $type);
  }
  return theme('apachesolr_search_results_page', $form, $results);
}