A platform for community discussion. Free, open, simple.
Revert "FIX: Incorrect search blurb when advanced search filters are used."
David Taylorcb1f8913926c
diff --git a/lib/search.rb b/lib/search.rbindex 8b868821bdf..2525591282b 100644--- a/lib/search.rb+++ b/lib/search.rb@@ -187,7 +187,7 @@ class Search@results = GroupedSearchResults.new(@opts[:type_filter],- term,+ clean_term,@search_context,@include_blurbs,@blurb_lengthdiff --git a/lib/search/grouped_search_results.rb b/lib/search/grouped_search_results.rbindex 75f75ab3f42..f5239018877 100644--- a/lib/search/grouped_search_results.rb+++ b/lib/search/grouped_search_results.rb@@ -30,14 +30,12 @@ class Searchattr_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 || BLURB_LENGTH+ @blurb_length = blurb_length || 200@posts = []@categories = []@users = []@@ -74,7 +72,7 @@ class Searchendend- def self.blurb_for(cooked, term = nil, blurb_length = BLURB_LENGTH)+ def self.blurb_for(cooked, term = nil, blurb_length = 200)blurb = nilcooked = SearchIndexer.scrub_html_for_search(cooked)@@ -93,11 +91,14 @@ class Searchendif term- if term =~ Regexp.new(Search::PHRASE_MATCH_REGEXP_PATTERN)- term = Regexp.last_match[1]+ terms = term.split(/\s+/)+ phrase = terms.first++ if phrase =~ Regexp.new(Search::PHRASE_MATCH_REGEXP_PATTERN)+ phrase = Regexp.last_match[1]end- blurb = TextHelper.excerpt(cooked, term,+ blurb = TextHelper.excerpt(cooked, phrase,radius: blurb_length / 2)enddiff --git a/spec/requests/search_controller_spec.rb b/spec/requests/search_controller_spec.rbindex ba24bf29058..044e741d54d 100644--- a/spec/requests/search_controller_spec.rb+++ b/spec/requests/search_controller_spec.rb@@ -101,25 +101,6 @@ describe SearchController doexpect(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' doget "/search/query.json", params: {@@ -160,6 +141,7 @@ describe SearchController doendit "should return the right result" do+get "/search/query.json", params: {term: user_post.topic_id,type_filter: 'topic',