如何在Drupal 7的一页上获得10个以上的搜索结果?


17

默认情况下,搜索页面仅显示10个结果。如何更改显示无限数量的结果?


1
对于那些对为什么现在无法做到这一点的背景故事感兴趣的人,请参阅:drupal.org/node/33809
coderintherye 2011年

我需要在Drupal 8中做同样的事情,但是我无法更改搜索结果的分页限制。你能帮上忙吗?
Naveen Kumar,

Answers:


15

我建议为此使用视图。视图附带了一个搜索视图(默认情况下处于禁用状态)。


感谢您的推荐。这看起来是最简单的方法,但是在Drupal 7中,我看不到任何搜索视图。
mivoligo 2011年

您可以在一个视图中最终配置视图,该视图显示诸如core search.module之类的搜索结果
Daniel Wehner



4

在Drupal 7中,我能够使用自定义模块中的hook_query_alter来修改每页的核心搜索结果项。如果您熟悉在代码中使用钩子,则可以使用以下代码片段:

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

我在视图模块中找不到“搜索视图”。我正在使用7.x-3.7视图。

为了在Drupal 7的一页上获得10多个搜索结果,我使用了search_config模块。我使用了最新版本“ 7.x-1.1-beta2”。

启用该模块后,您可以在“附加节点搜索配置”部分下的“配置”->“搜索”和“元数据”->“搜索设置(admin / config / search / settings)”中配置寻呼机限制。您将在此处看到“结果”部分,并且可以指定页面限制以在一页上显示10个以上的搜索结果。


这似乎不适用于Apache Solr。
杰克·瑞安

0

默认的搜索视图似乎已从“视图”模块中删除,因此我迅速将其删除,您可以将其用作满足自己需求的起点。使用“视图”导入对话框并粘贴代码以将其导入。

$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

您也可以使用搜索限制模块或在template.php中使用以下代码

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

$variables['quantity'] = 5; 

}
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.