Showing result count and result range in search results

ankur - May 11, 2005 - 21:55
Project:Drupal
Version:7.x-dev
Component:search.module
Category:feature request
Priority:normal
Assigned:David Lesieur
Status:needs work
Issue tags:Screenshot
Description

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

#1

Zen - March 4, 2006 - 16:46

Seconded.

#2

geodaniel - March 27, 2006 - 12:23
Assigned to:Anonymous» geodaniel
Status:active» needs work

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.

AttachmentSizeStatusTest resultOperations
search_counting.patch.txt990 bytesIgnoredNoneNone

#3

Steven - March 27, 2006 - 21:55

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.

#4

catch - September 17, 2007 - 13:24
Version:x.y.z» 7.x-dev

#5

moshe weitzman - January 6, 2008 - 16:56

subscribe. would be nice.

#6

robertDouglass - April 15, 2008 - 09:57

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.

#7

Rowanw - April 21, 2008 - 22:26

Subscribing.

#8

Rowanw - April 25, 2008 - 03:32

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:

#9

incrn8 - April 28, 2008 - 04:13

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.

#10

David Lesieur - May 10, 2008 - 00:52

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

AttachmentSizeStatusTest resultOperations
22627_theme_pager.patch4.75 KBIdlePassed: 9329 passes, 0 fails, 0 exceptionsView details | Re-test

#11

douggreen - May 10, 2008 - 21:00
Status:needs work» needs review

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.

AttachmentSizeStatusTest resultOperations
22627.patch3.56 KBIdlePassed: 9329 passes, 0 fails, 0 exceptionsView details | Re-test

#12

robertDouglass - May 10, 2008 - 21:21

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.

#13

David Lesieur - May 11, 2008 - 16:38

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. ;)

AttachmentSizeStatusTest resultOperations
22627_theme_pager.patch4.36 KBIdlePassed: 9348 passes, 0 fails, 0 exceptionsView details | Re-test

#14

David Lesieur - May 17, 2008 - 22:21

Re-rolled patch with unit tests.

AttachmentSizeStatusTest resultOperations
22627_theme_pager.patch8.72 KBIdlePassed: 9348 passes, 0 fails, 0 exceptionsView details | Re-test

#15

David Lesieur - May 17, 2008 - 23:15
Assigned to:geodaniel» David Lesieur

#16

douggreen - May 18, 2008 - 01:05

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.

#17

David Lesieur - May 18, 2008 - 15:30
Priority:minor» normal

Oops, yes! Done.

AttachmentSizeStatusTest resultOperations
22627_theme_pager.patch8.73 KBIdleUnable to apply patch 22627_theme_pager_2.patchView details | Re-test

#18

David Lesieur - May 18, 2008 - 15:45

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

AttachmentSizeStatusTest resultOperations
22627_theme_pager.patch8.39 KBIdleFailed: 9325 passes, 1 fail, 0 exceptionsView details | Re-test

#19

douggreen - May 19, 2008 - 01:02

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]));

#20

David Lesieur - May 19, 2008 - 02:13

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

AttachmentSizeStatusTest resultOperations
22627_theme_pager.patch8.36 KBIdlePassed: 9329 passes, 0 fails, 0 exceptionsView details | Re-test

#21

douggreen - May 19, 2008 - 11:19

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.

#22

douggreen - May 20, 2008 - 12:02
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.

#23

Dries - May 20, 2008 - 20:48

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.

#24

Dries - June 3, 2008 - 18:32
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.

#25

David Lesieur - June 18, 2008 - 14:14

@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.

#26

noahb - January 26, 2009 - 11:04

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...

AttachmentSizeStatusTest resultOperations
A.patch8.71 KBIgnoredNoneNone
B.patch10.31 KBIgnoredNoneNone
before_after.gif80.91 KBIgnoredNoneNone

#27

noahb - January 27, 2009 - 22:34
Status:needs work» needs review

CNR to test the patch.

#28

System Message - February 1, 2009 - 04:05
Status:needs review» needs work

The last submitted patch failed testing.

 
 

Drupal is a registered trademark of Dries Buytaert.