diff --git a/lib/search/grouped_search_results.rb b/lib/search/grouped_search_results.rb index 82d9be0095b..fbff4d64fe7 100644 --- a/lib/search/grouped_search_results.rb +++ b/lib/search/grouped_search_results.rb @@ -12,7 +12,7 @@ class Search def topic_ids topic_results = @by_type[:topic] return Set.new if topic_results.blank? - return topic_results.result_ids + return topic_results.results.map{|r| r.topic_id} end def as_json(options = nil) @@ -36,4 +36,4 @@ class Search end -end \ No newline at end of file +end diff --git a/lib/search/search_result.rb b/lib/search/search_result.rb index 4785c59f039..7f24b7853f1 100644 --- a/lib/search/search_result.rb +++ b/lib/search/search_result.rb @@ -5,7 +5,7 @@ class Search extend ActionView::Helpers::TextHelper end - attr_accessor :type, :id + attr_accessor :type, :id, :topic_id # Category attributes attr_accessor :color, :text_color @@ -16,7 +16,7 @@ class Search def initialize(row) row.symbolize_keys! @type = row[:type].to_sym - @url, @id, @title = row[:url], row[:id], row[:title] + @url, @id, @title, @topic_id = row[:url], row[:id], row[:title], row[:topic_id] end def as_json(options = nil) @@ -41,12 +41,15 @@ class Search end def self.from_topic(t, custom_title=nil) - SearchResult.new(type: :topic, id: t.id, title: custom_title || t.title, url: t.relative_url) + SearchResult.new(type: :topic, topic_id: t.id, id: t.id, title: custom_title || t.title, url: t.relative_url) end def self.from_post(p, context, term) custom_title = if context && context.id == p.topic_id + # TODO: rewrite this + # 1. convert markdown to text + # 2. grab full words excerpt = TextHelper.excerpt(p.raw, term.split(/\s+/)[0], radius: 30) excerpt = TextHelper.truncate(p.raw, length: 50) if excerpt.blank? I18n.t("search.within_post", @@ -60,9 +63,9 @@ class Search # we want the topic link when it's the OP SearchResult.from_topic(p.topic, custom_title) elsif context && context.id == p.topic_id - SearchResult.new(type: :topic, id: "_#{p.id}", title: custom_title, url: p.url) + SearchResult.new(type: :topic, topic_id: p.topic_id, id: "_#{p.id}", title: custom_title, url: p.url) else - SearchResult.new(type: :topic, id: p.topic.id, title: p.topic.title, url: p.url) + SearchResult.new(type: :topic, topic_id: p.topic_id, id: p.topic.id, title: p.topic.title, url: p.url) end end diff --git a/spec/components/search_spec.rb b/spec/components/search_spec.rb index 69e28061b84..8d9eaeb5553 100644 --- a/spec/components/search_spec.rb +++ b/spec/components/search_spec.rb @@ -157,6 +157,9 @@ describe Search do "_#{post4.id}", topic2.id] + # trigger expanded search + results = Search.new('birds', search_context: post1.topic).execute + end end