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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mo6’s picture

See also the discussion at: http://drupal.org/node/79744

zoo33’s picture

Status: Active » Needs review

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

zoo33’s picture

FileSize
1.03 KB

...and here's the file.

zoo33’s picture

FileSize
3.01 KB

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

sime’s picture

In the interest reducing variable explosion, maybe some generic variables that could be used by other modules.

variable_get('results_per_page_list',25)
variable_get('results_per_page_teaser',10)

Also, I wouldn't worry about this sort of thing:

$results_per_page = variable_get('results_per_page_list',25);

This just adds cruft and when you look at the variable_get function you'll see that you're not saving much code.

zoo33’s picture

Yes, 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?

zoo33’s picture

I've given the second patch some more thought and come to the conclusion that the calls to variable_get() really shouldn't be in do_search() but rather in the functions that call do_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 call do_query().

dww’s picture

Version: x.y.z » 6.x-dev
Status: Needs review » Closed (duplicate)

see http://drupal.org/node/33809 or http://drupal.org/node/39954 as 2 more general (and much older) issues about the same thing.