FIX: topic search order

When using the full page search and filtering down to a specific topic, the sort order was overwritten to by by "post_number".

This was confusing because we allow different type of sort order in the full search page.

This fixes it by only sorting by post_number when there's no "global" sort order defined.

Since the "new topic map" uses the search endpoint behind the scene, this also fixes the "most likes" popup.

Context - https://meta.discourse.org/t/searching-order-seems-to-be-broken-when-searching-in-topic/312303
This commit is contained in:
Régis Hanol
2024-06-27 17:51:39 +02:00
parent 4b111626cb
commit a56321efb5
2 changed files with 15 additions and 3 deletions

View File

@ -1191,9 +1191,9 @@ class Search
posts.where("topics.category_id in (?)", category_ids)
elsif is_topic_search
posts.where("topics.id = ?", @search_context.id).order(
"posts.post_number #{@order == :latest ? "DESC" : ""}",
)
posts = posts.where("topics.id = ?", @search_context.id)
posts = posts.order("posts.post_number ASC") unless @order
posts
elsif @search_context.is_a?(Tag)
posts =
posts.joins("LEFT JOIN topic_tags ON topic_tags.topic_id = topics.id").joins(