You are here

function search404_results in Search 404 7

Get the results for a search.

Parameters

array $keys: The search keys.

string $type_search: The search module to search.

Return value

array $results Renderable array of search results.

2 calls to search404_results()
search404_block_view in ./search404.module
Implements hook_block_view().
search404_page in ./search404.page.inc
Main search function.
1 string reference to 'search404_results'
search404_block_view in ./search404.module
Implements hook_block_view().

File

./search404.page.inc, line 320
The search404 module search page related functions.

Code

function search404_results($keys, $type_search) {

  // Called for apache solr, lucene, xapian and core search.
  $results = search_data($keys, $type_search);

  // Apache Solr puts the results in $results['search_results'].
  if (isset($results['search_results'])) {
    $results = $results['search_results'];
  }

  // Some modules like ds_search (#1253426) returns its own results format
  // and may not have $results['#results'].
  if (isset($results['#results'])) {

    // Jump to first result if there are results and
    // if there is only one result and if jump to first is selected or
    // if there are more than one results and force jump to first is selected.
    if (is_array($results['#results']) && (count($results['#results']) == 1 && variable_get('search404_jump', FALSE) || count($results['#results']) >= 1 && variable_get('search404_first', FALSE))) {
      if (isset($results['#results'][0]['node']->path)) {
        $result_path = $results['#results'][0]['node']->path;
      }
      else {
        $result_path = 'node/' . $results['#results'][0]['node']->nid;
      }
      search404_error_message($keys);
      search404_goto($result_path);
    }
    else {
      search404_error_message($keys);
      if (isset($results['#results']) && count($results['#results']) >= 1) {
        drupal_add_css(drupal_get_path('module', 'search') . '/search.css', 'module', 'all', FALSE);
      }
      else {
        $results = search_help('search#noresults', drupal_help_arg());
      }
    }
  }
  else {

    // Normal $results['#results'] doesn't exist, we will not redirect
    // and just hope the strange search module knows how to render its output.
    search404_error_message($keys);
  }
  return $results;
}