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

This is a revert of
d8c796bc44
and
5bf0a0893b.

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 commit is contained in:
Alan Guo Xiang Tan
2021-02-01 13:40:06 +08:00
parent 91fb298510
commit 4b3f65bb26
2 changed files with 49 additions and 87 deletions

View File

@ -601,8 +601,8 @@ describe Search do
expect(result.posts.pluck(:id)).to eq([post2.id, post.id])
end
it 'aggregates searches in a topic by returning the post with the highest rank' do
_post = Fabricate(:post, topic: topic, raw: "this is a play post")
it 'aggregates searches in a topic by returning the post with the lowest post number' do
post = Fabricate(:post, topic: topic, raw: "this is a play post")
post2 = Fabricate(:post, topic: topic, raw: "play play playing played play")
post3 = Fabricate(:post, raw: "this is a play post")
@ -613,7 +613,7 @@ describe Search do
results = Search.execute('play')
expect(results.posts.map(&:id)).to eq([
post2.id,
post.id,
post3.id
])
end
@ -1892,9 +1892,11 @@ describe Search do
it 'allows to define custom order' do
expect(Search.new("advanced").execute.posts).to eq([post1, post0])
Search.advanced_order(:chars) do |posts|
posts.reorder("(SELECT LENGTH(raw) FROM posts WHERE posts.topic_id = subquery.topic_id) DESC")
posts.reorder("MAX(LENGTH(posts.raw)) DESC")
end
expect(Search.new("advanced order:chars").execute.posts).to eq([post0, post1])
end
end