I was looking for a Google-like search results, e.g. "1-10 of about 100 for 'foo'". So here's a small addition I did in my template:

We can calculate how many search results we have based on the number of returned pages. For result pages that have less then a whole page, like a search with just a few hits, or the last page of a found set of results, we count the $results array for more accurate reporting.

Just go to your template.php file and add the following code:


function yourtheme_views_fastsearch_display(&$view, &$items, $type) {
  drupal_add_css(drupal_get_path('module', 'search') .'/search.css', 'module', 'all', FALSE);

  if (isset($items) && is_array($items) && count($items)) {
    // NOTE: using global to pass values from
    // views_fastsearch_views_handler_search_index
    global $_vfs_search_keys;
    if (isset($_vfs_search_keys)) {
      $keys = array();
      foreach ($_vfs_search_keys as $value) {
        $keys = array_merge($keys, $value);
      }
      $excerpt_keys = implode(' ', $keys);
    }
    
    $output = '<p>&nbsp;</p>';
    
  global $pager_page_array, $pager_total;
  //establish page variables
  $total_pages = $pager_total['0'];
  $total_page_count = $total_pages - 1;
  //approx number of results based on page count
  $approx_results = $total_pages * 10;
  //calculate range
  $page_number = $pager_page_array['0'];
  $start_result = $page_number * 10 + 1;
  $end_result = $page_number * 10 + 10;
  //get search term
  $search_term = $excerpt_keys;
  //remove page numbers and plus signs
  $search_term = explode('?', $search_term);
  $search_words = $search_term['0'];
  //check for a single page of results and count array
  if($total_pages == '1') {
    $found_set = count($items);
    $output .= '<div id="page_results">';
    $output .= 'Search results <strong>'. $start_result .' - '. $found_set .'</strong> of <strong>'. $found_set .'</strong> containing <strong>"'. $search_words .'"</strong>';
    $output .= '</div>';
  }
  elseif ($page_number == $total_page_count) {
    $found_set = count($items);
    $adjusted_end = $total_page_count * 10 + $found_set;
    $output .= '<div id="page_results">';
    $output .= 'Search results <strong>'. $start_result .' - '. $adjusted_end .'</strong> of <strong>'. $adjusted_end .'</strong> containing <strong>"'. $search_words.'"</strong>';
    $output .= '</div>';
  }
  else {
  $output .= '<div id="page_results">';
  $output .= 'Search results <strong>'. $start_result .' - '. $end_result .'</strong> of about <strong>'. $approx_results .'</strong> containing <strong>"'. $search_words .'"</strong>';
  $output .= '</div>';
  }
  $output .= '<div id="search_page">';
  $output .= '<dl class="search-results">';
  foreach ($items as $entry) {
    $output .= theme('search_item', $entry, $type);
  }
  $output .= '</dl>';
  $output .= '</div>';    

    $output .= '<dl class="search-results">';
    foreach ($items as $item) {
      // Build the node body.
      $node = node_load($item->nid);
      $node = node_build_content($node, FALSE, FALSE);
      $node->body = drupal_render($node->content);

      // Fetch comments for snippet
      $node->body .= module_invoke('comment', 'nodeapi', $node, 'update index');

      // Fetch terms for snippet
      $node->body .= module_invoke('taxonomy', 'nodeapi', $node, 'update index');

      $extra = node_invoke_nodeapi($node, 'search result');
      $entry = array(
        'link' => url('node/'. $item->nid, NULL, NULL, TRUE),
        'type' => node_get_types('name', $node),
        'title' => $node->title,
        'user' => theme('username', $node),
        'date' => $node->changed,
        'node' => $node,
        'view' => $view,
        'extra' => $extra,
        //Greg another change 'score' => $item->score,
        'snippet' => search_excerpt($excerpt_keys, $node->body)
      );
      $output .= theme('views_fastsearch_item', $entry, $type);
    }
    $output .= '</dl>';
    return $output;
  }
}


And that's it now your search results will show you something like the following example:

Search results 21 - 24 of 24 containing "hotels in Wichita"

Comments

droople’s picture

did not work for me, I have a theme called local, with is just a rename of garland.

pomliane’s picture

Status: Active » Closed (won't fix)

This version of Views Fast Search is not supported anymore. The issue is closed for this reason.
Please upgrade to a supported version and feel free to reopen the issue on the new version if applicable.

This issue has been automagically closed by a script.