['content', 'answers', 'comments'].each do |t|
break if results.length >= MAX_RESULTS
Question.search_tank('', :conditions => conditions.merge(t => "#{search_term}"), :page => 1, :per_page => 5).each do |q|
next if matched_qs.include? q.id
matched_qs << q.id
r = {:title => q.content, :value => app_question_url(q.app, q.id)}
if t == 'content'
r[:label] = highlight_matched(search_regex, q.content)
r[:label] << "<span class='search-type'>Question</span>"
else
r[:label] = q.content
end
if t == 'answers'
r[:label] = "<span class='search-type snippet'>Answer</span>" + [r[:label], get_snippet(search_regex, q.answers)].compact.join('<br />')
end
if t == 'comments'
r[:label] = "<span class='search-type snippet'>Comment</span>" + [r[:type], r[:label], get_snippet(search_regex, q.answers.map(&:comments).flatten)].compact.join('<br />')
end
results << r
break if results.length >= MAX_RESULTS
end
I would like to refactor that part which generates r[:label]
results = []
before the loop? are you missing anend
at the end? is this a helper? \$\endgroup\$results = []
before the loop and yes i missend
No this is no helper butsearch#new
action which render jsonresults.to_json
gist.github.com/6738554e438c741fba45 \$\endgroup\$