Same name and namespace in other branches
  1. 4.6.x modules/search.module \search_view()
  2. 4.7.x modules/search.module \search_view()
  3. 5.x modules/search/search.module \search_view()
  4. 7.x modules/search/search.pages.inc \search_view()

Menu callback; presents the search form and/or search results.

1 string reference to 'search_view'
search_menu in modules/search/search.module
Implementation of hook_menu().

File

modules/search/search.pages.inc, line 11
User page callbacks for the search module.

Code

function search_view($type = 'node') {

  // Search form submits with POST but redirects to GET. This way we can keep
  // the search query URL clean as a whistle:
  // search/type/keyword+keyword
  if (!isset($_POST['form_id'])) {
    if ($type == '') {

      // Note: search/node 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/node');
    }
    $keys = search_get_keys();

    // Only perform search if there is non-whitespace search term:
    $results = '';
    if (trim($keys)) {

      // Log the search keys:
      watchdog('search', '%keys (@type).', array(
        '%keys' => $keys,
        '@type' => module_invoke($type, 'search', 'name'),
      ), 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'), search_help('search#noresults', drupal_help_arg()));
      }
    }

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