diff --git a/phpBB/phpbb/search/backend/fulltext_native.php b/phpBB/phpbb/search/backend/fulltext_native.php index fb340b2d98..b0a3d2ebd9 100644 --- a/phpBB/phpbb/search/backend/fulltext_native.php +++ b/phpBB/phpbb/search/backend/fulltext_native.php @@ -955,9 +955,9 @@ class fulltext_native extends base implements search_backend_interface // If using mysql and the total result count is not calculated yet, get it from the db if (!$total_results && $is_mysql) { - $sql_count = str_replace("SELECT {$sql_array['SELECT']}", "SELECT COUNT({$sql_array['SELECT']})", $sql); + $sql_count = str_replace("SELECT {$sql_array['SELECT']}", "SELECT COUNT({$sql_array['SELECT']}) as total_results", $sql); $result = $this->db->sql_query($sql_count); - $total_results = count($this->db->sql_fetchrowset($result)); + $total_results = $sql_array['GROUP_BY'] ? count($this->db->sql_fetchrowset($result)) : $this->db->sql_fetchfield('total_results'); $this->db->sql_freeresult($result); if (!$total_results) diff --git a/tests/functional/search/base.php b/tests/functional/search/base.php index f60e404622..d5f6980a3a 100644 --- a/tests/functional/search/base.php +++ b/tests/functional/search/base.php @@ -51,6 +51,30 @@ abstract class phpbb_functional_search_base extends phpbb_functional_test_case $this->assertStringContainsString("Search found $topics_found match", $crawler->filter('.searchresults-title')->text(), $this->search_backend); } + protected function assert_search_in_topic($topic_id, $keywords, $posts_found, $sort_key = '') + { + $this->purge_cache(); + $crawler = self::request('GET', "search.php?t=$topic_id&sf=msgonly&keywords=$keywords" . ($sort_key ? "&sk=$sort_key" : '')); + $this->assertEquals($posts_found, $crawler->filter('.postbody')->count(), $this->search_backend); + $this->assertStringContainsString("Search found $posts_found match", $crawler->filter('.searchresults-title')->text(), $this->search_backend); + } + + protected function assert_search_in_forum($forum_id, $keywords, $posts_found, $sort_key = '') + { + $this->purge_cache(); + $crawler = self::request('GET', "search.php?fid[]=$forum_id&keywords=$keywords" . ($sort_key ? "&sk=$sort_key" : '')); + $this->assertEquals($posts_found, $crawler->filter('.postbody')->count(), $this->search_backend); + $this->assertStringContainsString("Search found $posts_found match", $crawler->filter('.searchresults-title')->text(), $this->search_backend); + } + + protected function assert_search_topics_in_forum($forum_id, $keywords, $topics_found, $sort_key = '') + { + $this->purge_cache(); + $crawler = self::request('GET', "search.php?fid[]=$forum_id&sr=topics&keywords=$keywords" . ($sort_key ? "&sk=$sort_key" : '')); + $this->assertEquals($topics_found, $crawler->filter('.row')->count(), $this->search_backend); + $this->assertStringContainsString("Search found $topics_found match", $crawler->filter('.searchresults-title')->text(), $this->search_backend); + } + protected function assert_search_not_found($keywords) { $crawler = self::request('GET', 'search.php?keywords=' . $keywords); @@ -150,6 +174,10 @@ abstract class phpbb_functional_search_base extends phpbb_functional_test_case $this->assert_search_found_topics('phpbb3+installation', 1, $sort_key); $this->assert_search_found_topics('foosubject+barsearch', 1, $sort_key); + $this->assert_search_in_forum(2, 'multiple+search+results', 3, $sort_key); // test multiple results count - forum search - posts + $this->assert_search_topics_in_forum(2, 'multiple+search+results', 2, $sort_key); // test multiple results count - forum search - topics + $this->assert_search_in_topic((int) $topic_multiple_results_count1['topic_id'], 'multiple+results', 2, $sort_key); // test multiple results count - topic search + $this->assert_search_posts_by_author('searchforauthoruser', 2, $sort_key); $this->assert_search_topics_by_author('searchforauthoruser', 1, $sort_key); }