Permalink
Browse files

Show owner icon and starred state in search results

  • Loading branch information...
1 parent da36b08 commit 743a1e23005979ecaf05cf0e2f0407f2922172ad @rwdaigle committed Nov 21, 2012
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -25,6 +25,9 @@
background: #D8EBFA
text-shadow: none
+ div.choice .meta
+ float: right
+
div.hints
background: #EBEBEB
color: #555
@@ -1,7 +1,7 @@
module GistsHelper
def search_result_link(result)
- text = (result.highlight && result.highlight.description) ? result.highlight['description'].first.html_safe : result.description
+ text = result.description
text = "<em>Untitled</em>".html_safe if text.blank?
link_to(text, result.url, :class => 'gist-url')
end
View
@@ -8,12 +8,16 @@ class Gist < ActiveRecord::Base
belongs_to :user
has_many :files, :class_name => 'GistFile', :dependent => :delete_all
+ scope :with_ids, lambda { |ids| ids.any? ? where(["id in (?)", ids]) : "1 = 0"}
+
index_name ELASTICSEARCH_INDEX_NAME
mapping do
indexes :description, :analyzer => 'snowball', :boost => 10
indexes :gh_created_at, type: 'date'
indexes :user_id, :analyzer => :not_analyzed
+ indexes :owner_gh_username, analyzer: 'keyword'
+ indexes :starred, :analyzer => :not_analyzed
indexes :files do
indexes :filename, analyzer: 'standard', :boost => 5
indexes :content, analyzer: 'snowball'
@@ -75,8 +79,12 @@ def search(user, q)
end
end
+ # Return actual gists, not results
+ gist_ids = results.collect { |r| r.id }.uniq
+ gists = Gist.with_ids(gist_ids)
+
log({ns: self, fn: __method__, query: q, measure: true, at: 'search-results'}, {:'result-count' => results.size}, user)
- results
+ gists
end
def reindex(gists = scoped)
@@ -115,9 +123,12 @@ def to_indexed_json
def indexed_attributes
{
user_id: user_id,
+ owner_gh_username: owner_gh_username,
+ owner_gh_avatar_url: owner_gh_avatar_url,
description: description,
url: url,
public: public?,
+ starred: starred?,
gh_created_at: gh_created_at,
gh_updated_at: gh_updated_at,
comment_count: comment_count,
@@ -4,6 +4,10 @@
.choice
%span.command= search_result_link(result)
%span.description= pluralize(result.comment_count, "comments")
+ %span.meta
+ - if result.starred?
+ = image_tag("star.png")
+ %img(src="#{result.owner_gh_avatar_url}&s=13" title="#{result.owner_gh_username}" alt="#{result.owner_gh_username}")
.hints
%em keyboard:
↑ = up, ↓ = down, enter = follow link, / = search

0 comments on commit 743a1e2

Please sign in to comment.