mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 09:28:03 +08:00
FIX: Post blurb incorrect when search contains a phrase match.
If the blurb generated is not around the search term, we will not be able to highlight it on the client side.
This commit is contained in:
@ -304,16 +304,35 @@ describe Search do
|
||||
end
|
||||
|
||||
context 'searching for a post' do
|
||||
let!(:reply) { Fabricate(:basic_reply, topic: topic, user: topic.user) }
|
||||
let(:result) { Search.execute('quotes', type_filter: 'topic', include_blurbs: true) }
|
||||
let!(:reply) do
|
||||
Fabricate(:post_with_long_raw_content,
|
||||
topic: topic,
|
||||
user: topic.user,
|
||||
).tap { |post| post.update!(raw: "#{post.raw} elephant") }
|
||||
end
|
||||
|
||||
let(:expected_blurb) do
|
||||
"...to satisfy any test conditions that require content longer than the typical test post raw content. elephant"
|
||||
end
|
||||
|
||||
it 'returns the post' do
|
||||
expect(result).to be_present
|
||||
expect(result.posts.length).to eq(1)
|
||||
p = result.posts[0]
|
||||
expect(p.topic.id).to eq(topic.id)
|
||||
expect(p.id).to eq(reply.id)
|
||||
expect(result.blurb(p)).to eq("this reply has no quotes")
|
||||
result = Search.execute('elephant',
|
||||
type_filter: 'topic',
|
||||
include_blurbs: true
|
||||
)
|
||||
|
||||
expect(result.posts).to contain_exactly(reply)
|
||||
expect(result.blurb(reply)).to eq(expected_blurb)
|
||||
end
|
||||
|
||||
it 'returns the right post and blurb for searches with phrase' do
|
||||
result = Search.execute('"elephant"',
|
||||
type_filter: 'topic',
|
||||
include_blurbs: true
|
||||
)
|
||||
|
||||
expect(result.posts).to contain_exactly(reply)
|
||||
expect(result.blurb(reply)).to eq(expected_blurb)
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user