Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I'd like to have the number of of search results to be configurable. At the moment it is a constant in do_search
(module search).
// Do actual search query
$result = pager_query("SELECT * FROM temp_search_results", 10, 0, $count_query);
In some situations, for example using search in a e-commerce site displaying small (graphical) teasers/product images, you'd wish to display more results.
Comment | File | Size | Author |
---|---|---|---|
#4 | search_res_per_page-2.patch | 3.01 KB | zoo33 |
#3 | search_res_per_page-1.patch | 1.03 KB | zoo33 |
Comments
Comment #1
mo6See also the discussion at: http://drupal.org/node/79744
Comment #2
zoo33 CreditAttribution: zoo33 commentedI just encountered the same problem while developing a module that calls do_search(). I'd like to see an argument added to do_search(), something like:
$results_per_page = 10
or:
$results_per_page = variable_get('search_results_per_page',10)
I made a very simple patch of the first suggestion above. It's against HEAD. Would be great if someone who has worked on this module before would review it.
Comment #3
zoo33 CreditAttribution: zoo33 commented...and here's the file.
Comment #4
zoo33 CreditAttribution: zoo33 commented...and here's another patch that takes the other approach and adds a setting for the number of search results to display. I must confess that I haven't had the time to test it yet, but I'll try to do that asap.
The first one is perhaps "safer" to commit since we're in a code freeze. Neither of them requires any changes to other code however.
Comment #5
simeIn the interest reducing variable explosion, maybe some generic variables that could be used by other modules.
Also, I wouldn't worry about this sort of thing:
This just adds cruft and when you look at the variable_get function you'll see that you're not saving much code.
Comment #6
zoo33 CreditAttribution: zoo33 commentedYes, it might be a good idea to centralize the number of posts per page setting. On the other hand, you might want different settings for the front page, taxonomy lists, forums etc. I don't really care – all I need is the new argument for
do_search()
.Anyone in favor of the first patch? Any other ideas?
Comment #7
zoo33 CreditAttribution: zoo33 commentedI've given the second patch some more thought and come to the conclusion that the calls to
variable_get()
really shouldn't be indo_search()
but rather in the functions that calldo_search()
.So I'm in favor of committing the first patch and leave
do_query()
like that. When that is done we can consider if we should add the user setting and use that in any functions that calldo_query()
.Comment #8
dwwsee http://drupal.org/node/33809 or http://drupal.org/node/39954 as 2 more general (and much older) issues about the same thing.