I am able to reproduce this bug on a clean d7.21 with views 7.x-3.6 and 7.x-3.5

All I did was create a single node with some text in the body and created a view of all node types with Search Term added to the filter and exposed. When I search for a single word or multiple words that are over the minimum word length it works. When I search for two words, one over the minimum length and one under the view returns multiple entries of the one node. Using Distinct does not help either.

The text I used in the body of my node was
"This is a test of the emergency broadcasting system!"

Searching for "emergency" returns the node
Searching for "emergency system" returns the node
Searching for "emergency a" returns the node twice.

I also tested this search on the default search system www.site.com/search and it works fine.

Here is an export of the view I created

$view = new view();
$view->name = 'test_search';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'test search';
$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'] = 'test search';
$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['query']['options']['distinct'] = TRUE;
$handler->display->display_options['query']['options']['pure_distinct'] = TRUE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'node';
/* 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;
/* Sort criterion: Content: Post date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'node';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* 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';
$handler->display->display_options['filters']['keys']['expose']['remember_roles'] = array(
2 => '2',
1 => 0,
3 => 0,
);

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

Comments

StevenJay’s picture

After further investigation I believe this is caused by the 'score' field being added to the GROUP_BY list in the search. Because score is almost always unique search results are never grouped and therefore not counted properly. All the views fields are added to the GROUP_BY including the score based on the logic in the views_plugin_query_default.inc files query function around line 1328.

For those who need a quick fix I used hook_views_pre_execute to remove the score from the group.

/*
 * Implementation of hook_views_pre_execute
 */
function MODULE_NAME_views_pre_execute(&$view) {
  if ($view->name == 'VIEW_NAME') {
    //there seems to be a bug in views that use the search term as a filter
    // which adds the score field to the groupby 
    // since each score is unique the rows are never grouped 
    // this prevents any aggregation so the unique search results are not counted properly
    $group_by = &$view->build_info['query']->getGroupBy();
    unset($group_by['score']);
    $group_by = &$view->build_info['count_query']->getGroupBy();
    unset($group_by['score']);
  }
}
codewhisper’s picture

Thanks for the hint. This solves the problem on my side as well!

TechNikh’s picture

Awesome!. that worked like a charm.
now searching with quotes doesn't return multiple results.

esmerel’s picture

Status: Active » Fixed
TechNikh’s picture

Status: Fixed » Active

isin't this a bug and should be committed to views module?

esmerel’s picture

Status: Active » Fixed

If someone wants to make a patch and see if it'll get committed, sure. It looks to me more or less like that's how it has to work, but if one of the other maintainers wants to disagree, that's fine too.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Added an example

happysnowmantech’s picture

This is likely a duplicate of #1677692: Remove duplicates from exposed search filter results. I believe a fix has been commited.

For problems like the "GROUP BY score" mentioned in #1, or if you go from having duplicates to having fewer than expected results, also try related issue #1615438: Search terms: nodes dont appear when using multiple arguments.