From 1408563a7fc369003f45348b856935e72fd0b265 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 26 Jun 2015 17:37:14 +1000 Subject: [PATCH] HACK: allow for multiple hits on same topic for search --- lib/topic_query.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/topic_query.rb b/lib/topic_query.rb index 5d35c226236..6bda1c0abc5 100644 --- a/lib/topic_query.rb +++ b/lib/topic_query.rb @@ -92,7 +92,10 @@ class TopicQuery .joins("JOIN (#{sql}) X on X.id = topics.id") .order("X.pos") - posts_map = Hash[*search.posts.map{|p| [p.topic_id, p]}.flatten] + posts_map = {} + search.posts.each do |p| + (posts_map[p.topic_id] ||= []) << p + end end end @@ -107,8 +110,10 @@ class TopicQuery list.topics.each do |topic| - if post = posts_map[topic.id] - topic.search_data = {excerpt: search.blurb(post), post_number: post.post_number} + if posts = posts_map[topic.id] + if post = posts.shift + topic.search_data = {excerpt: search.blurb(post), post_number: post.post_number} + end end end