Skip to content

Commit

Permalink
Use real topic id
Browse files Browse the repository at this point in the history
Signed by Shawn Bulen, [email protected]
  • Loading branch information
sbulen committed Oct 25, 2024
1 parent 9b9d19b commit b971a1e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Sources/Search/SearchApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,8 @@ public function searchQuery(array $query_params, array $searchWords, array $excl
'
SELECT ' . (empty($this->params['topic']) ? 'lsr.id_topic' : $this->params['topic'] . ' AS 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)' : '') . '
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = lsr.id_msg)
INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)' : '') . '
WHERE lsr.id_search = {int:id_search}' . $approve_query . '
ORDER BY {raw:sort} {raw:sort_dir}
LIMIT {int:start}, {int:max}',
Expand Down Expand Up @@ -1768,6 +1769,9 @@ protected function searchSubjectAndMessage()
],
];

// Most searches are at the topic-level, and do not list message-level results.
// Message-level results are displayed when doing searches within topics
// and when showing complete results ("Show results as messages" option).
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';
Expand All @@ -1778,6 +1782,7 @@ protected function searchSubjectAndMessage()
$main_query['group_by'][] = 't.id_topic';
} else {
// This is outrageous!
// Note we're stuffing id_msg in an id_topic column to get past the db contraint.
$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

0 comments on commit b971a1e

Please sign in to comment.