Perhaps this request has been made before, but I was wondering: why don't we display the number of results (we're passing a SQL COUNT query to pager_query() anyway) as well as the range of results currently being displayed on the search results page.

Kind of like how google will say "Results 1 - 10 of about 76 for "blah blah".

-Ankur

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Zen’s picture

Seconded.

geodaniel’s picture

Assigned: Unassigned » geodaniel
Status: Active » Needs work
FileSize
990 bytes

The attached patch adds '[total] results found for [query], showing page [current] of [max]' to the top of the search pages.

I attempted to get it to show actual result counts (eg. 1-10, 11-20, etc) per page but couldn't figure out how to intercept that information from between the search and pager functions. If anyone knows how to get that info, please update the patch, as showing result numbers is probably more useful than page numbers.

Steven’s picture

The patch is not escaping the search keys, leading to XSS issues.

You could argue that this is a theming issue though. The Civicspace theme changes theme_pager() so it already returns a summary like this patch.

catch’s picture

Version: x.y.z » 7.x-dev
moshe weitzman’s picture

subscribe. would be nice.

robertDouglass’s picture

Nice feature request. I agree with Steven that this is a pager issue. The best solution would be to come up with a theme pager function that gets that encapsulates this code:

+        if ($pager_total[0] > 1) {
+          $searchsummary .= t(', showing page %page of %totalpages', array('%page' => $pager_page_array[0] + 1, '%totalpages' => $pager_total[0]));
+        }

And then recycles it in the search display.

Rowanw’s picture

Subscribing.

Rowanw’s picture

can't find file to patch at input line 3
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|--- search.module-47b4 2006-03-23 15:56:26.000000000 +0100
|+++ search.module      2006-03-27 14:14:03.000000000 +0200
--------------------------
File to patch:
davemybes’s picture

Here's a link to some code I created to get the 1-10,11-20...etc. for paged results: http://drupal.org/node/201969. Hope this helps.

David Lesieur’s picture

FileSize
4.75 KB

LIVE FROM THE MINNESOTA SEARCH SPRINT: Here's a first step... We'll probably want to add some default CSS for the pager information.

douggreen’s picture

Status: Needs work » Needs review
FileSize
3.56 KB

Here's a second attempt, that I think is a little less invasive. It changes the name from pager_info to pager_range, calls it from the search result theming, rather than adding an argument to theme_pager, and lets the search results template print the pager wherever it wants.

robertDouglass’s picture

My opinion is that theme_pager_range isn't a theme function. It has global variables, math, and a PHP control structure. I would want to see that done in a normal function and have those values passed into a real theme function that just outputs HTML.

David Lesieur’s picture

FileSize
4.36 KB

I've added a new pager_describe_range() function that takes the logic away from the theme function.

I've also moved the pager range above the search results, which is closer to what Google does. ;)

David Lesieur’s picture

FileSize
8.72 KB

Re-rolled patch with unit tests.

David Lesieur’s picture

Assigned: geodaniel » David Lesieur
douggreen’s picture

If $pager_total_items[$element] <= 1, $from and $to are not used. You might want to assign them in the conditional where they are used.

David Lesieur’s picture

Priority: Minor » Normal
FileSize
8.73 KB

Oops, yes! Done.

David Lesieur’s picture

FileSize
8.39 KB

Removed the unneeded declaration of $pager_total from pager_describe_range().

douggreen’s picture

One more comment, FWIW,

    if ($from == $to) {
      return t('Item @to of @total', array('@to' => $to, '@total' => $pager_total_items[$element]));
    }
    elseif ($pager_total_items[$element] <= $limit) {
      return t('@total items', array('@total' => $pager_total_items[$element]));
    }
    else {
      return t('Items @from - @to of @total', array('@from' => $from, '@to' => $to, '@total' => $pager_total_items[$element]));
    }   

... could be two lines shorter, but it may be clearer the way it is ... I'm not sure what the Drupal standard is here.

    if ($from == $to) {
      return t('Item @to of @total', array('@to' => $to, '@total' => $pager_total_items[$element]));
    }
    elseif ($pager_total_items[$element] <= $limit) {
      return t('@total items', array('@total' => $pager_total_items[$element]));
    }
    return t('Items @from - @to of @total', array('@from' => $from, '@to' => $to, '@total' => $pager_total_items[$element]));
David Lesieur’s picture

FileSize
8.36 KB

I prefer your shorter version. Here's the patch!

douggreen’s picture

I applied the patch. Because there's a new theme function, I had to force rebuilding the theme and code registries. I tested the display on the first couple pages, and on the last page of a large results set. I tested the display on an empty results set. I also ran the new pager tests.

I had a hard time finding the pager test on admin/build/testing because this test is now it's own section. Should we group the test with the search tests or system tests or something else. Other than this question with where to group the pager test on admin/build/testing, I think that this is RTBC.

douggreen’s picture

Status: Needs review » Reviewed & tested by the community

I have a question above about where the test should live, but that's possibly a question for Dries, so I'm marking this RTBC.

Dries’s picture

I reviewed this patch and it all looks good. The only point I have is that it doesn't look attractive visually.

I'd recommend the following: (i) we remove the title 'Search results' and (ii) make a new dynamic title "Found x items".

I think that would remove some clutter and make it look a bit more visually appealing.

Dries’s picture

Status: Reviewed & tested by the community » Needs work

I'm going to mark this 'code needs work' to see if we can improve the visuals a bit. If we can't, I'll commit it as is.

David Lesieur’s picture

@Dries: Do you see the dynamic title completely replacing the pager range description proposed in the patch?

I think a more useful title would include the search keywords, although it probably wouldn't fit very well with how the search results page is currently designed.

bcn’s picture

FileSize
80.91 KB
10.31 KB
8.71 KB

The first attachment (A.patch) is mostly a re-roll of the patch from #20, with one small change. I removed the title text ("Search Results"), and moved the test to the simpletest directory.

The second attachment (B.patch) is based of the first one, but I changed the formatting a bit, and added the search sting. I wasn't sure of the right way to find the search string, so this one is more of a functional prototype as opposed to a ready to commit patch...

bcn’s picture

Status: Needs work » Needs review
Issue tags: +Screenshot

CNR to test the patch.

Status: Needs review » Needs work

The last submitted patch failed testing.

jhodgdon’s picture

Version: 7.x-dev » 8.x-dev

Sigh. Yet another issue that didn't make it into Drupal 7, and needs to be postponed to Drupal 8.

rasumo’s picture

Here's a solution (far from perfect) that's implemented at the theming layer.

Code for template.php:

function MYTHEME_preprocess_search_results(&$variables) {

  //Get search terms
  $keys = search_get_keys();   
    
  // define the number of results being shown on a page
  $itemsPerPage = 10;
  
  // get the current page
  $currentPage = $_REQUEST['page']+1;

  // get the total number of results from the $GLOBALS
  $total = $GLOBALS['pager_total_items'][0];
    
  // perform calculation
  $start = 10*$currentPage-9;
  $end = $itemsPerPage * $currentPage;
  if ($end>$total) $end = $total;
    
  // set this html to the $variables
  $variables['MYTHEME_search_totals'] = "Displaying $start - $end of $total results for <b>$keys</b>";
}

Code for search-results.tpl.php:

<?php print $MYTHEME_search_totals; ?> 

Example Result: Displaying 1 - 3 of 3 results for "INSERT TERM HERE"

NOTE: When using Apache Solr for search and you let it take over taxonomy handling, this approach may produce undesired results (working on a solution).

BeaPower’s picture

Is this default for views in d7 or I still need to use the code in #30?

TechNikh’s picture

jhodgdon’s picture

Version: 8.0.x-dev » 8.1.x-dev
Issue summary: View changes

Since 8.0.x-beta1 has been released, our policy at this point is No feature requests until 8.1.x. See #2350615: [policy, no patch] What changes can be accepted during the Drupal 8 beta phase?. Sorry, it's just too late for 8.0.x at this point, so even if we had a viable patch, the core committers would not commit it. So unless we decide this is a Task or a Bug (and I don't think it is), we'll have to delay it.

David Lesieur’s picture

Assigned: David Lesieur » Unassigned

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

xeM8VfDh’s picture

is this still being looked into for D8? I'd like this enhancement.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

tyler36’s picture

Status: Needs work » Closed (won't fix)

I am going to close this because there has been no progress in 8+ years.