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

FIX: Select earliest post when aggregating posts in a topic for search. #11914

Merged
merged 1 commit into from Feb 5, 2021

Conversation

tgxworld
Copy link
Contributor

@tgxworld tgxworld commented Feb 1, 2021

This is a revert of
d8c796b
and
5bf0a08.

Linking to the post within a topic that has the highest rank was
confusing users and hard to explain because ranking is determined via
the PG ranking function. See the following meta topics for the
complaints after we switch to the new ordering:

  1. https://meta.discourse.org/t/title-search-not-working-as-expected/157737
  2. https://meta.discourse.org/t/search-results-should-prioritize-first-post-in-topic-when-title-matches-search-term/175154

This is a revert of
discourse@d8c796b
and
discourse@5bf0a08.

Linking to the post within a topic that has the highest rank was
confusing users and hard to explain because ranking is determined via
the PG ranking function. See the following meta topics for the
complaints after we switch to the new ordering:

1. https://meta.discourse.org/t/title-search-not-working-as-expected/157737
2. https://meta.discourse.org/t/search-results-should-prioritize-first-post-in-topic-when-title-matches-search-term/175154
Search.advanced_order(:chars) do |posts|
posts.reorder("(SELECT LENGTH(raw) FROM posts WHERE posts.topic_id = subquery.topic_id) DESC")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lis2 Which plugin was using this advanced order? I need to fix that plugin as the query will break.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@discoursebot
Copy link

This pull request has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/search-results-should-prioritize-first-post-in-topic-when-title-matches-search-term/175154/28

@tgxworld tgxworld added performance ruby Pull requests that update Ruby code labels Feb 1, 2021
"MAX(subquery.created_at) created_at"
)
.order("created_at DESC")
posts = posts.order("MAX(posts.created_at) DESC")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is that MAX function used here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're doing aggregation with group, we need to use an aggregation function in the ordering as well. In this case, the latest post in the topic is returned.

@tgxworld tgxworld merged commit 4b3f65b into discourse:master Feb 5, 2021
@tgxworld tgxworld deleted the revert_search_behavior branch February 5, 2021 01:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance ruby Pull requests that update Ruby code
4 participants