From 737b99966de8e12ffa13d762b7065043a39399d7 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 10 Nov 2012 03:39:51 +0530 Subject: [PATCH] [ticket/11179] add search query in case initial one fails changes the start parameter according to the total search results and executes the search query again to get the results. PHPBB3-11179 --- phpBB/includes/search/fulltext_mysql.php | 34 ++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 324c214e91..acb1a7bde8 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -381,7 +381,6 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base { return $result_count; } - $id_ary = array(); $join_topic = ($type == 'posts') ? false : true; @@ -490,7 +489,38 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base if (!sizeof($id_ary)) { - return false; + $sql_count = "SELECT COUNT(*) as result_count + FROM $sql_from$sql_sort_table" . POSTS_TABLE . " p + WHERE MATCH ($sql_match) AGAINST ('" . $this->db->sql_escape(htmlspecialchars_decode($this->search_query)) . "' IN BOOLEAN MODE) + $sql_where_options + ORDER BY $sql_sort"; + $result = $this->db->sql_query($sql_count); + $total_match_count = (int) $this->db->sql_fetchfield('result_count'); + + if ($total_match_count) + { + if ($start < 0) + { + $start = 0; + } + else if ($start >= $total_match_count) + { + $start = floor(($total_match_count - 1) / $per_page) * $per_page; + } + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); + while ($row = $this->db->sql_fetchrow($result)) + { + $id_ary[] = (int) $row[$field]; + } + $this->db->sql_freeresult($result); + + $id_ary = array_unique($id_ary); + } + + if (!sizeof($id_ary)) + { + return false; + } } // if the total result count is not cached yet, retrieve it from the db