Permalink
Browse files

Add meta data styling and output to search results

  • Loading branch information...
1 parent 1b67550 commit c2ae17c9b3933da92b0a45c30c0346913264a2d7 @rwdaigle committed Oct 12, 2012
Showing with 11 additions and 3 deletions.
  1. +6 −0 app/helpers/gists_helper.rb
  2. +1 −1 app/models/gist.rb
  3. +4 −2 app/views/gists/search.html.haml
@@ -12,4 +12,10 @@ def files_display(result)
content_tag(:script, nil, :src => "#{result.url}.js?file=#{file.filename}")
end.join("<br/>").html_safe
end
+
+ def search_result_styles(result)
+ styles = result.public? ? 'public' : 'private'
+ styles += result.starred? ? ' starred' : ''
+ styles += ' ' + result['files.language'].collect(&:downcase).uniq.join(' ')
+ end
end
View
@@ -55,7 +55,7 @@ def search(user, q)
log({ns: self, fn: __method__, query: q, measure: true}, user) do
tire.search do
query { string q }
- fields [:description, :url, :public, :gh_updated_at, :id]
+ fields [:description, :url, :public, :gh_updated_at, :id, :'files.filename', :'files.language']
# sort { by :gh_created_at, 'desc' }
filter :term, :user_id => user.id
highlight :description, :options => { :tag => "<em>" }
@@ -17,7 +17,9 @@
- if @results.size > 0
%ul.search-results
- for result in @results
- %li
- %p= search_result_link(result)
+ %li(style="#{search_result_styles(result)}")
+ = search_result_link(result)
+ %span.meta= "modified #{distance_of_time_in_words_to_now(result.gh_updated_at)} ago"
+ / %p= result.inspect
- else
%p= "No results found for \"#{params[:q]}\""

0 comments on commit c2ae17c

Please sign in to comment.