Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Filter querying by current user

  • Loading branch information...
commit 014c43b5691e0aed3023a1b6c6f1a27178618d12 1 parent 90c2308
@rwdaigle authored
View
2  app/controllers/gists_controller.rb
@@ -9,7 +9,7 @@ def index
end
def search
- @results = Gist.search params[:q]
+ @results = Gist.search(current_user, params[:q])
end
def refresh
View
7 app/models/gist.rb
@@ -11,6 +11,7 @@ class Gist < ActiveRecord::Base
mapping do
indexes :description, :analyzer => 'snowball', :boost => 10
indexes :gh_created_at, type: 'date'
+ indexes :user_id, :analyzer => :not_analyzed
indexes :files do
indexes :filename, analyzer: 'keyword'
indexes :content, analyzer: 'snowball'
@@ -44,11 +45,12 @@ def import(gh_gist)
end
end
- def search(q)
- log(ns: self, fn: __method__, query: q) do
+ def search(user, q)
+ log({ns: self, fn: __method__, query: q}, user) do
tire.search do
query { string q }
sort { by :gh_created_at, 'desc' }
+ filter :term, :user_id => user.id
highlight :description, :'files.content'
end
end
@@ -73,6 +75,7 @@ def to_indexed_json
def indexed_attributes
{
+ user_id: user_id,
description: description,
url: url,
public: public?,
View
1  app/views/gists/search.html.haml
@@ -2,6 +2,7 @@
%ul
- for result in @results
+ / %p= result.inspect
- if result.highlight
%li
%p= link_to((result.highlight.description ? result.highlight['description'].first.html_safe : result.description), result.url)
Please sign in to comment.
Something went wrong with that request. Please try again.