diff options
| author | Dhruv <dhruv.goel92@gmail.com> | 2012-12-03 00:48:19 +0530 |
|---|---|---|
| committer | Oleg Pudeyev <oleg@bsdpower.com> | 2012-12-30 18:50:05 -0500 |
| commit | 979edc4113f8b9ecb3aa4e7d445a5b59eefd78ff (patch) | |
| tree | 5ee56ed347072e6bd31d45c505a642fdd5fca8df /phpBB/includes/search/fulltext_postgres.php | |
| parent | 4dcc8cabae670e0ee57a489e7e13c2f93d99753a (diff) | |
| download | forums-979edc4113f8b9ecb3aa4e7d445a5b59eefd78ff.tar forums-979edc4113f8b9ecb3aa4e7d445a5b59eefd78ff.tar.gz forums-979edc4113f8b9ecb3aa4e7d445a5b59eefd78ff.tar.bz2 forums-979edc4113f8b9ecb3aa4e7d445a5b59eefd78ff.tar.xz forums-979edc4113f8b9ecb3aa4e7d445a5b59eefd78ff.zip | |
[ticket/11188] add count query to postgres search
PHPBB3-11188
Diffstat (limited to 'phpBB/includes/search/fulltext_postgres.php')
| -rw-r--r-- | phpBB/includes/search/fulltext_postgres.php | 11 |
1 files changed, 10 insertions, 1 deletions
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); |
