FIX: Incorrect search blurb when advanced search filters are used take2

Also remove include_blurbs attribute which isn't used.
This commit is contained in:
Guo Xiang Tan
2020-07-14 11:05:57 +08:00
parent 919c87a9ce
commit ce39733b1a
6 changed files with 65 additions and 36 deletions

View File

@@ -427,7 +427,7 @@ describe Search do
context 'searching the OP' do
let!(:post) { Fabricate(:post_with_long_raw_content) }
let(:result) { Search.execute('hundred', type_filter: 'topic', include_blurbs: true) }
let(:result) { Search.execute('hundred', type_filter: 'topic') }
it 'returns a result correctly' do
expect(result.posts.length).to eq(1)
@@ -449,8 +449,7 @@ describe Search do
it 'returns the post' do
result = Search.execute('elephant',
type_filter: 'topic',
include_blurbs: true
type_filter: 'topic'
)
expect(result.posts).to contain_exactly(reply)
@@ -459,8 +458,7 @@ describe Search do
it 'returns the right post and blurb for searches with phrase' do
result = Search.execute('"elephant"',
type_filter: 'topic',
include_blurbs: true
type_filter: 'topic'
)
expect(result.posts).to contain_exactly(reply)
@@ -1492,7 +1490,7 @@ describe Search do
results = Search.execute('ragis', type_filter: 'topic')
expect(results.posts.length).to eq(1)
results = Search.execute('Rágis', type_filter: 'topic', include_blurbs: true)
results = Search.execute('Rágis', type_filter: 'topic')
expect(results.posts.length).to eq(1)
# TODO: this is a test we need to fix!
@@ -1514,7 +1512,7 @@ describe Search do
results = Search.execute('regis', type_filter: 'topic')
expect(results.posts.length).to eq(0)
results = Search.execute('Régis', type_filter: 'topic', include_blurbs: true)
results = Search.execute('Régis', type_filter: 'topic')
expect(results.posts.length).to eq(1)
expect(results.blurb(results.posts.first)).to include('Régis')

View File

@@ -53,7 +53,7 @@ describe SearchController do
get "/search/query.json", headers: {
"HTTP_X_REQUEST_START" => "t=#{start_time.to_f}"
}, params: {
term: "hi there", include_blurb: true
term: "hi there"
}
expect(response.status).to eq(409)
@@ -80,7 +80,7 @@ describe SearchController do
term = "hello\0hello"
get "/search/query.json", params: {
term: term, include_blurb: true
term: term
}
expect(response.status).to eq(400)
@@ -88,7 +88,7 @@ describe SearchController do
it "can search correctly" do
get "/search/query.json", params: {
term: 'awesome', include_blurb: true
term: 'awesome'
}
expect(response.status).to eq(200)
@@ -101,6 +101,24 @@ describe SearchController do
expect(data['topics'][0]['id']).to eq(awesome_post.topic_id)
end
it "can search correctly with advanced search filters" do
awesome_post.update!(
raw: "#{"a" * Search::GroupedSearchResults::BLURB_LENGTH} elephant"
)
get "/search/query.json", params: { term: 'order:views elephant' }
expect(response.status).to eq(200)
data = response.parsed_body
expect(data.dig("grouped_search_result", "term")).to eq('order:views elephant')
expect(data['posts'].length).to eq(1)
expect(data['posts'][0]['id']).to eq(awesome_post.id)
expect(data['posts'][0]['blurb']).to include('elephant')
expect(data['topics'][0]['id']).to eq(awesome_post.topic_id)
end
it 'performs the query with a type filter' do
get "/search/query.json", params: {
@@ -141,7 +159,6 @@ describe SearchController do
end
it "should return the right result" do
get "/search/query.json", params: {
term: user_post.topic_id,
type_filter: 'topic',