Skip to content

Commit

Permalink
Merge pull request SimpleMachines#8458 from Sesquipedalian/2.1/search…
Browse files Browse the repository at this point in the history
…_topic

[2.1] Returns correct search results when post moderation is enabled
  • Loading branch information
Sesquipedalian authored Feb 16, 2025
2 parents 4a23d61 + 5403276 commit 1cc691b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
6 changes: 2 additions & 4 deletions Sources/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,7 @@ function PlushSearch2()
'select' => array(
'id_search' => $_SESSION['search_cache']['id_search'],
'relevance' => '0',
'id_topic' => 't.id_topic',
),
'weights' => array(),
'from' => '{db_prefix}topics AS t',
Expand All @@ -1306,7 +1307,6 @@ function PlushSearch2()

if (empty($search_params['topic']) && empty($search_params['show_complete']))
{
$main_query['select']['id_topic'] = 't.id_topic';
$main_query['select']['id_msg'] = 'MAX(m.id_msg) AS id_msg';
$main_query['select']['num_matches'] = 'COUNT(*) AS num_matches';

Expand All @@ -1316,8 +1316,6 @@ function PlushSearch2()
}
else
{
// This is outrageous!
$main_query['select']['id_topic'] = 'm.id_msg AS id_topic';
$main_query['select']['id_msg'] = 'm.id_msg';
$main_query['select']['num_matches'] = '1 AS num_matches';

Expand Down Expand Up @@ -1849,7 +1847,7 @@ function PlushSearch2()
// *** Retrieve the results to be shown on the page
$participants = array();
$request = $smcFunc['db_search_query']('', '
SELECT ' . (empty($search_params['topic']) ? 'lsr.id_topic' : $search_params['topic'] . ' AS id_topic') . ', lsr.id_msg, lsr.relevance, lsr.num_matches
SELECT lsr.id_topic, lsr.id_msg, lsr.relevance, lsr.num_matches
FROM {db_prefix}log_search_results AS lsr' . ($search_params['sort'] == 'num_replies' || !empty($approve_query) ? '
INNER JOIN {db_prefix}topics AS t ON (t.id_topic = lsr.id_topic)' : '') . '
WHERE lsr.id_search = {int:id_search}' . $approve_query . '
Expand Down
2 changes: 1 addition & 1 deletion other/install_2-1_mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ CREATE TABLE {$db_prefix}log_search_results (
id_msg INT UNSIGNED NOT NULL DEFAULT '0',
relevance SMALLINT UNSIGNED NOT NULL DEFAULT '0',
num_matches SMALLINT UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (id_search, id_topic)
PRIMARY KEY (id_search, id_topic, id_msg)
) ENGINE={$engine};

#
Expand Down
2 changes: 1 addition & 1 deletion other/install_2-1_postgresql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ CREATE TABLE {$db_prefix}log_search_results (
id_msg bigint NOT NULL DEFAULT '0',
relevance smallint NOT NULL DEFAULT '0',
num_matches smallint NOT NULL DEFAULT '0',
PRIMARY KEY (id_search, id_topic)
PRIMARY KEY (id_search, id_topic, id_msg)
);

#
Expand Down
9 changes: 9 additions & 0 deletions other/upgrade_2-1_mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3902,4 +3902,13 @@ foreach($files AS $filename)
unset($_GET['last_action_id']);
unset($_GET['total_fixes']);
---}
---#

/******************************************************************************/
--- Improving search results storage
/******************************************************************************/

---# Updating primary key for log_search_results table
ALTER TABLE {$db_prefix}log_search_results DROP PRIMARY KEY;
ALTER TABLE {$db_prefix}log_search_results ADD PRIMARY KEY (id_search, id_topic, id_msg);
---#
9 changes: 9 additions & 0 deletions other/upgrade_2-1_postgresql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4264,4 +4264,13 @@ foreach($files AS $filename)
unset($_GET['last_action_id']);
unset($_GET['total_fixes']);
---}
---#

/******************************************************************************/
--- Improving search results storage
/******************************************************************************/

---# Updating primary key for log_search_results table
ALTER TABLE {$db_prefix}log_search_results DROP PRIMARY KEY;
ALTER TABLE {$db_prefix}log_search_results ADD PRIMARY KEY (id_search, id_topic, id_msg);
---#

0 comments on commit 1cc691b

Please sign in to comment.