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

@@ -23,19 +23,20 @@ class Search
:more_users,
:term,
:search_context,
:include_blurbs,
:more_full_page_results,
:error
)
attr_accessor :search_log_id
def initialize(type_filter, term, search_context, include_blurbs, blurb_length)
BLURB_LENGTH = 200
def initialize(type_filter:, term:, search_context:, blurb_length: nil, blurb_term: nil)
@type_filter = type_filter
@term = term
@blurb_term = blurb_term || term
@search_context = search_context
@include_blurbs = include_blurbs
@blurb_length = blurb_length || 200
@blurb_length = blurb_length || BLURB_LENGTH
@posts = []
@categories = []
@users = []
@@ -57,7 +58,7 @@ class Search
end
def blurb(post)
GroupedSearchResults.blurb_for(post.cooked, @term, @blurb_length)
GroupedSearchResults.blurb_for(post.cooked, @blurb_term, @blurb_length)
end
def add(object)
@@ -72,7 +73,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 +92,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