17

By default search page shows only 10 results. How can I change it to display unlimited number of results?

  • 1
    For those interested in back story as to why this is not currently possible to do easily see: drupal.org/node/33809 – coderintherye Mar 3 '11 at 0:37
  • I needed to do same in Drupal 8 and i am not able to change the pagination limit of search results. can you help on this.? – Naveen Kumar Aug 5 at 12:39
15

I recommend using views for this. Views comes with a search view included (disabled by default). Use an exposed search term filter to provide the search functionality, and customize other aspects of the view as needed.

  • Thanks for recommendation. It looks like easiest way, but in Drupal 7, I don't see any search view included. – mivoligo Mar 5 '11 at 12:30
  • You can definitive configure views in a view that it displays the search results like core search.module – Daniel Wehner Nov 2 '11 at 19:53
11

The 10 item limit is generally hard-coded into hook_search_execute() implementations (like node_search_execute()): in theory, you could implement hook_search_execute() and change the ->limit(10) query to something other than 10.

But as beeradb mentioned, it's probably easier to just use Views to override the core search results.

5

Drupal does not currently give you an option to change the number of search results per page. As @beeradb suggests, you can use the Views module (video tutorial for D7 at http://lin-clark.com/blog/intro-drupal-7-intro-views-pt-1).

There is a feature request for this to go into Drupal 8 http://drupal.org/node/702940.

4

In Drupal 7, I have been able to modify the core search result items per page using hook_query_alter in a custom module. The following code snippet can be used, if you're familiar with using hooks in code:

<?php
/**
 * Implements hook_query_alter
 */
function MY_MODULE_query_alter(&$query) {

  // This is a search result query and we want to change the
  // number of search results per page to 16.
  if ($query instanceof PagerDefault
    && ($tables = $query->getTables())
    && isset($tables['i']['table'])
    && $tables['i']['table'] === 'search_index') {
    $query->limit(16);
  }
}
0

I didn't find 'search view' in views module. I am using views 7.x-3.7.

To get more than 10 search results on one page in Drupal 7, I have used search_config module. I used it's latest version '7.x-1.1-beta2'.

Once the module is enabled, you can configure the pager limit from Configuration->Search and metadata->Search settings (admin/config/search/settings) under 'ADDITIONAL NODE SEARCH CONFIGURATION' section. You will see 'Results' section there and you can specify pager limit to show more than 10 search results on one page.

  • This does not seem to work with Apache Solr. – Jack Ryan Feb 4 '14 at 23:54
0

The default search view seems to have been removed from the Views module, so here's one I knocked up quickly that you can use as a starting point for your own requirements. Use the Views import dialogue and paste in the code to import it.

$view = new view();
$view->name = 'search_test';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'search test';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'search test';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'input_required';
$handler->display->display_options['exposed_form']['options']['text_input_required'] = 'Enter some search keywords.';
$handler->display->display_options['exposed_form']['options']['text_input_required_format'] = 'filtered_html';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '20';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* No results behavior: Global: Text area */
$handler->display->display_options['empty']['area']['id'] = 'area';
$handler->display->display_options['empty']['area']['table'] = 'views';
$handler->display->display_options['empty']['area']['field'] = 'area';
$handler->display->display_options['empty']['area']['empty'] = TRUE;
$handler->display->display_options['empty']['area']['content'] = 'No results found.';
$handler->display->display_options['empty']['area']['format'] = 'filtered_html';
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Search: Search Terms */
$handler->display->display_options['filters']['keys']['id'] = 'keys';
$handler->display->display_options['filters']['keys']['table'] = 'search_index';
$handler->display->display_options['filters']['keys']['field'] = 'keys';
$handler->display->display_options['filters']['keys']['operator'] = 'required';
$handler->display->display_options['filters']['keys']['exposed'] = TRUE;
$handler->display->display_options['filters']['keys']['expose']['operator_id'] = 'keys_op';
$handler->display->display_options['filters']['keys']['expose']['label'] = 'Search Terms';
$handler->display->display_options['filters']['keys']['expose']['operator'] = 'keys_op';
$handler->display->display_options['filters']['keys']['expose']['identifier'] = 'keys';

/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['path'] = 'search';
-2

You can use search limit module too or use following code in template.php

if(arg(0) == "search" && arg(1) == "site") {

$variables['quantity'] = 5; 

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.