From 1c399dcab707eef1d0a1c3c45557bdcdd3bb8ba2 Mon Sep 17 00:00:00 2001 From: rxu Date: Tue, 6 May 2025 00:11:45 +0700 Subject: [PATCH] [ticket/17491] Consistently apply array_unique to search results PHPBB-17491 --- phpBB/phpbb/search/fulltext_mysql.php | 9 ++++----- phpBB/phpbb/search/fulltext_native.php | 4 ++++ phpBB/phpbb/search/fulltext_postgres.php | 10 ++++------ 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/phpBB/phpbb/search/fulltext_mysql.php b/phpBB/phpbb/search/fulltext_mysql.php index 577cf412f3..e839ef86eb 100644 --- a/phpBB/phpbb/search/fulltext_mysql.php +++ b/phpBB/phpbb/search/fulltext_mysql.php @@ -609,7 +609,6 @@ class fulltext_mysql extends \phpbb\search\base } $this->db->sql_freeresult($result); - $id_ary = array_unique($id_ary); // if the total result count is not cached yet, retrieve it from the db if (!$result_count && count($id_ary)) { @@ -635,10 +634,10 @@ class fulltext_mysql extends \phpbb\search\base $id_ary[] = (int) $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); $id_ary = array_slice($id_ary, 0, (int) $per_page); @@ -896,10 +895,10 @@ class fulltext_mysql extends \phpbb\search\base $id_ary[] = (int) $row[$field]; } $this->db->sql_freeresult($result); - - $id_ary = array_unique($id_ary); } + $id_ary = array_unique($id_ary); + if (count($id_ary)) { $this->save_ids($search_key, '', $author_ary, $result_count, $id_ary, $start, $sort_dir); diff --git a/phpBB/phpbb/search/fulltext_native.php b/phpBB/phpbb/search/fulltext_native.php index a2d4dab98e..8df80d2772 100644 --- a/phpBB/phpbb/search/fulltext_native.php +++ b/phpBB/phpbb/search/fulltext_native.php @@ -1012,6 +1012,8 @@ class fulltext_native extends \phpbb\search\base $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, $this->search_query, $author_ary, $total_results, $id_ary, $start, $sort_dir); $id_ary = array_slice($id_ary, 0, (int) $per_page); @@ -1313,6 +1315,8 @@ class fulltext_native extends \phpbb\search\base $this->db->sql_freeresult($result); } + $id_ary = array_unique($id_ary); + if (count($id_ary)) { $this->save_ids($search_key, '', $author_ary, $total_results, $id_ary, $start, $sort_dir); diff --git a/phpBB/phpbb/search/fulltext_postgres.php b/phpBB/phpbb/search/fulltext_postgres.php index 5a16b4eed3..be2b7f704c 100644 --- a/phpBB/phpbb/search/fulltext_postgres.php +++ b/phpBB/phpbb/search/fulltext_postgres.php @@ -545,8 +545,6 @@ class fulltext_postgres extends \phpbb\search\base } $this->db->sql_freeresult($result); - $id_ary = array_unique($id_ary); - // if the total result count is not cached yet, retrieve it from the db if (!$result_count) { @@ -576,10 +574,10 @@ class fulltext_postgres extends \phpbb\search\base $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); $id_ary = array_slice($id_ary, 0, (int) $per_page); @@ -858,10 +856,10 @@ class fulltext_postgres extends \phpbb\search\base $id_ary[] = (int) $row[$field]; } $this->db->sql_freeresult($result); - - $id_ary = array_unique($id_ary); } + $id_ary = array_unique($id_ary); + if (count($id_ary)) { $this->save_ids($search_key, '', $author_ary, $result_count, $id_ary, $start, $sort_dir);