diff options
author | 2012-11-10 14:17:38 +0100 | |
---|---|---|
committer | 2013-02-19 00:52:44 +0530 | |
commit | 1c9c666ef193942a2d88ec59741ddc49900e92e9 (patch) | |
tree | 3fe65632dd13d3f7bd071cfd86774f5e0945637f /phpBB/includes/search/fulltext_mysql.php | |
parent | [ticket/11179] pass start parameter by reference (diff) | |
download | phpbb-1c9c666ef193942a2d88ec59741ddc49900e92e9.tar.gz phpbb-1c9c666ef193942a2d88ec59741ddc49900e92e9.tar.bz2 phpbb-1c9c666ef193942a2d88ec59741ddc49900e92e9.zip |
[ticket/11179] use FOUND_ROWS query to re-search with changed start param
PHPBB3-11179
Diffstat (limited to 'phpBB/includes/search/fulltext_mysql.php')
-rw-r--r-- | phpBB/includes/search/fulltext_mysql.php | 60 |
1 files changed, 22 insertions, 38 deletions
diff --git a/phpBB/includes/search/fulltext_mysql.php b/phpBB/includes/search/fulltext_mysql.php index 749353b2ee..3ecc2cd39d 100644 --- a/phpBB/includes/search/fulltext_mysql.php +++ b/phpBB/includes/search/fulltext_mysql.php @@ -375,6 +375,11 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base implode(',', $author_ary) ))); + if ($start < 0) + { + $start = 0; + } + // try reading the results from cache $result_count = 0; if ($this->obtain_ids($search_key, $result_count, $id_ary, $start, $per_page, $sort_dir) == SEARCH_RESULT_IN_CACHE) @@ -487,47 +492,11 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base $id_ary = array_unique($id_ary); - if (!sizeof($id_ary)) - { - $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 if (!$result_count) { - $sql = 'SELECT FOUND_ROWS() as result_count'; - $result = $this->db->sql_query($sql); + $sql_found_rows = 'SELECT FOUND_ROWS() as result_count'; + $result = $this->db->sql_query($sql_found_rows); $result_count = (int) $this->db->sql_fetchfield('result_count'); $this->db->sql_freeresult($result); @@ -537,6 +506,21 @@ class phpbb_search_fulltext_mysql extends phpbb_search_base } } + if ($start >= $result_count) + { + $start = floor(($result_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); + // store the ids, from start on then delete anything that isn't on the current page because we only need ids for one page $this->save_ids($search_key, implode(' ', $this->split_words), $author_ary, $result_count, $id_ary, $start, $sort_dir); $id_ary = array_slice($id_ary, 0, (int) $per_page); |