From 979edc4113f8b9ecb3aa4e7d445a5b59eefd78ff Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 3 Dec 2012 00:48:19 +0530 Subject: [ticket/11188] add count query to postgres search PHPBB3-11188 --- phpBB/includes/search/fulltext_postgres.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/search/fulltext_postgres.php') diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index f22ee2ca16..a9b122931b 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -476,6 +476,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base $tmp_sql_match[] = "to_tsvector ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', " . $sql_match_column . ") @@ to_tsquery ('" . $this->db->sql_escape($this->config['fulltext_postgres_ts_name']) . "', '" . $this->db->sql_escape($this->tsearch_query) . "')"; } + $this->db->sql_transaction('begin'); $sql = "SELECT $sql_select FROM $sql_from$sql_sort_table" . POSTS_TABLE . " p WHERE (" . implode(' OR ', $tmp_sql_match) . ") @@ -499,7 +500,13 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base // if the total result count is not cached yet, retrieve it from the db if (!$result_count) { - $result_count = sizeof ($id_ary); + $sql_count = "SELECT COUNT(*) as result_count + FROM $sql_from$sql_sort_table" . POSTS_TABLE . " p + WHERE (" . implode(' OR ', $tmp_sql_match) . ") + $sql_where_options"; + $result = $this->db->sql_query($sql_count); + $result_count = (int) $this->db->sql_fetchfield('result_count'); + $this->db->sql_freeresult($result); if (!$result_count) { @@ -507,6 +514,8 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base } } + $this->db->sql_transaction('commit'); + // 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); -- cgit v1.2.1 From 763f2929babcb65b503a60f712bfc552f1e296f9 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Mon, 3 Dec 2012 01:07:47 +0530 Subject: [ticket/11188] add result count query for author search PHPBB3-11188 --- phpBB/includes/search/fulltext_postgres.php | 34 ++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/search/fulltext_postgres.php') diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index a9b122931b..7d7b3f6fa8 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -656,6 +656,8 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base $field = 'topic_id'; } + $this->db->sql_transaction('begin'); + // Only read one block of posts from the db and then cache it $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); @@ -668,7 +670,35 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base // retrieve the total result count if needed if (!$result_count) { - $result_count = sizeof ($id_ary); + if ($type == 'posts') + { + $sql_count = "SELECT COUNT(*) as result_count + FROM " . $sql_sort_table . POSTS_TABLE . ' p' . (($firstpost_only) ? ', ' . TOPICS_TABLE . ' t ' : ' ') . " + WHERE $sql_author + $sql_topic_id + $sql_firstpost + $m_approve_fid_sql + $sql_fora + $sql_sort_join + $sql_time"; + } + else + { + $sql_count = "SELECT COUNT(*) as result_count + FROM " . $sql_sort_table . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p + WHERE $sql_author + $sql_topic_id + $sql_firstpost + $m_approve_fid_sql + $sql_fora + AND t.topic_id = p.topic_id + $sql_sort_join + $sql_time + GROUP BY t.topic_id, $sort_by_sql[$sort_key]"; + } + + $result = $this->db->sql_query($sql_count); + $result_count = (int) $this->db->sql_fetchfield('result_count'); if (!$result_count) { @@ -676,6 +706,8 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base } } + $this->db->sql_transaction('commit'); + if (sizeof($id_ary)) { $this->save_ids($search_key, '', $author_ary, $result_count, $id_ary, $start, $sort_dir); -- cgit v1.2.1 From 3d27ed13f5ac960fc24a3f95e39c767be4a48f31 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 29 Dec 2012 19:34:21 -0500 Subject: [ticket/11188] Reduce waste. PHPBB3-11188 --- phpBB/includes/search/fulltext_postgres.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'phpBB/includes/search/fulltext_postgres.php') diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index 7d7b3f6fa8..1475cc31d0 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -477,10 +477,13 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base } $this->db->sql_transaction('begin'); + + $sql_from = "FROM $sql_from$sql_sort_table" . POSTS_TABLE . " p"; + $sql_where = "WHERE (" . implode(' OR ', $tmp_sql_match) . ") + $sql_where_options"; $sql = "SELECT $sql_select - FROM $sql_from$sql_sort_table" . POSTS_TABLE . " p - WHERE (" . implode(' OR ', $tmp_sql_match) . ") - $sql_where_options + $sql_from + $sql_where ORDER BY $sql_sort"; $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); @@ -501,9 +504,8 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base if (!$result_count) { $sql_count = "SELECT COUNT(*) as result_count - FROM $sql_from$sql_sort_table" . POSTS_TABLE . " p - WHERE (" . implode(' OR ', $tmp_sql_match) . ") - $sql_where_options"; + $sql_from + $sql_where"; $result = $this->db->sql_query($sql_count); $result_count = (int) $this->db->sql_fetchfield('result_count'); $this->db->sql_freeresult($result); -- cgit v1.2.1 From 2cb48f034153038d71d89ab58904cd048b8524d9 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 10 Nov 2012 15:35:05 +0100 Subject: [ticket/11179] correct start parameter in psql keyword search PHPBB3-11179 --- phpBB/includes/search/fulltext_postgres.php | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'phpBB/includes/search/fulltext_postgres.php') diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index 1475cc31d0..d968a934f4 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -371,6 +371,11 @@ class phpbb_search_fulltext_postgres 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) @@ -495,11 +500,6 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base $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) { @@ -518,6 +518,21 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base $this->db->sql_transaction('commit'); + 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[] = $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); -- cgit v1.2.1 From ef88edbcf69541bd79e220c87c444b33a6751c67 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 10 Nov 2012 15:44:16 +0100 Subject: [ticket/11179] correct start param in author search of postgres PHPBB3-11179 --- phpBB/includes/search/fulltext_postgres.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'phpBB/includes/search/fulltext_postgres.php') diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index d968a934f4..e8a5353b05 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -583,6 +583,11 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base $author_name, ))); + 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) @@ -725,6 +730,20 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base $this->db->sql_transaction('commit'); + 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); + if (sizeof($id_ary)) { $this->save_ids($search_key, '', $author_ary, $result_count, $id_ary, $start, $sort_dir); -- cgit v1.2.1 From bc77ca4d4eb6a5bcf3e47706c6b6fd2b0fe33f82 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sat, 10 Nov 2012 15:45:15 +0100 Subject: [ticket/11179] pass start param by reference in postgres PHPBB3-11179 --- phpBB/includes/search/fulltext_postgres.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/search/fulltext_postgres.php') diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index e8a5353b05..bdc2fa4f19 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -343,7 +343,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ - public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) { // No keywords? No posts if (!$this->search_query) @@ -559,7 +559,7 @@ class phpbb_search_fulltext_postgres extends phpbb_search_base * @param int $per_page number of ids each page is supposed to contain * @return boolean|int total number of results */ - public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) + public function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page) { // No author? No posts if (!sizeof($author_ary)) -- cgit v1.2.1 From 8b7f306897cddcb16cbed50488848ee357c26f39 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Sun, 2 Dec 2012 14:31:12 +0530 Subject: [ticket/11179] fix success query path for postgres Additional query to check start parameter executed only incase of no results. PHPBB3-11179 --- phpBB/includes/search/fulltext_postgres.php | 32 ++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'phpBB/includes/search/fulltext_postgres.php') diff --git a/phpBB/includes/search/fulltext_postgres.php b/phpBB/includes/search/fulltext_postgres.php index bdc2fa4f19..eeb628b18f 100644 --- a/phpBB/includes/search/fulltext_postgres.php +++ b/phpBB/includes/search/fulltext_postgres.php @@ -521,17 +521,17 @@ class phpbb_search_fulltext_postgres 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); + $result = $this->db->sql_query_limit($sql, $this->config['search_block_size'], $start); - while ($row = $this->db->sql_fetchrow($result)) - { - $id_ary[] = $row[$field]; - } - $this->db->sql_freeresult($result); + while ($row = $this->db->sql_fetchrow($result)) + { + $id_ary[] = $row[$field]; + } + $this->db->sql_freeresult($result); - $id_ary = array_unique($id_ary); + $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); @@ -733,16 +733,16 @@ class phpbb_search_fulltext_postgres 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); + $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); + $id_ary = array_unique($id_ary); + } if (sizeof($id_ary)) { -- cgit v1.2.1