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

[3.0] Returns correct search results when post moderation is enabled #8459

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/SearchApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ public function searchQuery(array $query_params, array $searchWords, array $excl
$request = Db::$db->search_query(
'',
'
SELECT ' . (empty($this->params['topic']) ? 'lsr.id_topic' : $this->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' . ($this->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 Expand Up @@ -1728,6 +1728,7 @@ protected function searchSubjectAndMessage()
'select' => [
'id_search' => $_SESSION['search_cache']['id_search'],
'relevance' => '0',
'id_topic' => 't.id_topic',
],
'weights' => [],
'from' => '{db_prefix}topics AS t',
Expand All @@ -1751,16 +1752,13 @@ protected function searchSubjectAndMessage()
];

if (empty($this->params['topic']) && empty($this->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';

$main_query['weights'] = self::$weight_factors;

$main_query['group_by'][] = 't.id_topic';
} 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
2 changes: 1 addition & 1 deletion other/install_3-0_MySQL.sql
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,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_3-0_PostgreSQL.sql
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,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_3-0_MySQL.sql
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,15 @@ ALTER TABLE {$db_prefix}log_packages
ADD COLUMN smf_version VARCHAR(5) NOT NULL DEFAULT '';
---#

/******************************************************************************/
--- 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);
---#

/******************************************************************************/
--- Updating Settings
/******************************************************************************/
Expand Down
9 changes: 9 additions & 0 deletions other/upgrade_3-0_PostgreSQL.sql
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,15 @@ ALTER TABLE {$db_prefix}log_packages
ADD COLUMN IF NOT EXISTS smf_version VARCHAR(5) NOT NULL DEFAULT '';
---#

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

---# Improving search results storage
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);
---#

/******************************************************************************/
--- Updating Settings
/******************************************************************************/
Expand Down