FIX: Limits for PM and group header search (#16887)

When searching for PMs or PMs in a group inbox, results in the header search were not being limited to 5 with a "More" link to the full page search. This PR fixes that.

It also simplifies the logic and updates the search API docs to include recently added `in:messages` and `group_messages:groupname` options.
This commit is contained in:
Penar Musaraj
2022-05-24 11:31:24 -04:00
committed by GitHub
parent 0403a8633b
commit 8222810099
5 changed files with 49 additions and 11 deletions
+35 -3
View File
@@ -2183,24 +2183,26 @@ describe Search do
let!(:post3) { Fabricate(:post, raw: 'hello hello hello') }
let!(:post4) { Fabricate(:post, raw: 'hello hello') }
let!(:post5) { Fabricate(:post, raw: 'hello') }
before do
Search.stubs(:per_filter).returns(number_of_results)
end
it 'returns more results flag' do
results = Search.execute('hello', type_filter: 'topic')
results2 = Search.execute('hello', type_filter: 'topic', page: 2)
results = Search.execute('hello', search_type: :full_page, type_filter: 'topic')
results2 = Search.execute('hello', search_type: :full_page, type_filter: 'topic', page: 2)
expect(results.posts.length).to eq(number_of_results)
expect(results.posts.map(&:id)).to eq([post1.id, post2.id])
expect(results.more_full_page_results).to eq(true)
expect(results2.posts.length).to eq(number_of_results)
expect(results2.posts.map(&:id)).to eq([post3.id, post4.id])
expect(results2.more_full_page_results).to eq(true)
end
it 'correctly search with page parameter' do
search = Search.new('hello', type_filter: 'topic', page: 3)
search = Search.new('hello', search_type: :full_page, type_filter: 'topic', page: 3)
results = search.execute
expect(search.offset).to eq(2 * number_of_results)
@@ -2209,6 +2211,36 @@ describe Search do
expect(results.more_full_page_results).to eq(nil)
end
it 'returns more results flag for header searches' do
results = Search.execute('hello', search_type: :header)
expect(results.posts.length).to eq(Search.per_facet)
expect(results.more_posts).to eq(nil) # not 6 posts yet
post6 = Fabricate(:post, raw: 'hello post #6')
results = Search.execute('hello', search_type: :header)
expect(results.posts.length).to eq(Search.per_facet)
expect(results.more_posts).to eq(true)
end
end
context 'header in-topic search' do
let!(:topic) { Fabricate(:topic, title: 'This is a topic with a bunch of posts') }
let!(:post1) { Fabricate(:post, topic: topic, raw: 'hola amiga') }
let!(:post2) { Fabricate(:post, topic: topic, raw: 'hola amigo') }
let!(:post3) { Fabricate(:post, topic: topic, raw: 'hola chica') }
let!(:post4) { Fabricate(:post, topic: topic, raw: 'hola chico') }
let!(:post5) { Fabricate(:post, topic: topic, raw: 'hola hermana') }
let!(:post6) { Fabricate(:post, topic: topic, raw: 'hola hermano') }
let!(:post7) { Fabricate(:post, topic: topic, raw: 'hola chiquito') }
it 'does not use per_facet pagination' do
search = Search.new('hola', search_type: :header, search_context: topic)
results = search.execute
expect(results.posts.length).to eq(7)
expect(results.more_posts).to eq(nil)
end
end
context 'in:tagged' do