Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.1] Returns correct search results when post moderation is enabled #8458

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
---#