mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 11:23:25 +08:00
FIX: Incorrect search blurb when advanced search filters are used.
This commit is contained in:
parent
26dc981285
commit
2e1eafae06
|
@ -187,7 +187,7 @@ class Search
|
|||
|
||||
@results = GroupedSearchResults.new(
|
||||
@opts[:type_filter],
|
||||
clean_term,
|
||||
term,
|
||||
@search_context,
|
||||
@include_blurbs,
|
||||
@blurb_length
|
||||
|
|
|
@ -30,12 +30,14 @@ class Search
|
|||
|
||||
attr_accessor :search_log_id
|
||||
|
||||
BLURB_LENGTH = 200
|
||||
|
||||
def initialize(type_filter, term, search_context, include_blurbs, blurb_length)
|
||||
@type_filter = type_filter
|
||||
@term = term
|
||||
@search_context = search_context
|
||||
@include_blurbs = include_blurbs
|
||||
@blurb_length = blurb_length || 200
|
||||
@blurb_length = blurb_length || BLURB_LENGTH
|
||||
@posts = []
|
||||
@categories = []
|
||||
@users = []
|
||||
|
@ -72,7 +74,7 @@ class Search
|
|||
end
|
||||
end
|
||||
|
||||
def self.blurb_for(cooked, term = nil, blurb_length = 200)
|
||||
def self.blurb_for(cooked, term = nil, blurb_length = BLURB_LENGTH)
|
||||
blurb = nil
|
||||
cooked = SearchIndexer.scrub_html_for_search(cooked)
|
||||
|
||||
|
@ -91,14 +93,11 @@ class Search
|
|||
end
|
||||
|
||||
if term
|
||||
terms = term.split(/\s+/)
|
||||
phrase = terms.first
|
||||
|
||||
if phrase =~ Regexp.new(Search::PHRASE_MATCH_REGEXP_PATTERN)
|
||||
phrase = Regexp.last_match[1]
|
||||
if term =~ Regexp.new(Search::PHRASE_MATCH_REGEXP_PATTERN)
|
||||
term = Regexp.last_match[1]
|
||||
end
|
||||
|
||||
blurb = TextHelper.excerpt(cooked, phrase,
|
||||
blurb = TextHelper.excerpt(cooked, term,
|
||||
radius: blurb_length / 2
|
||||
)
|
||||
end
|
||||
|
|
|
@ -101,6 +101,25 @@ 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', include_blurb: true
|
||||
}
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
data = response.parsed_body
|
||||
|
||||
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 +160,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',
|
||||
|
|
Loading…
Reference in New Issue
Block a user