Permalink
Browse files

Search importing.

  • Loading branch information...
1 parent ff0a2bd commit 60876c59feb66d7cd9890fd3f807d7d0ab794e66 @benubois benubois committed Oct 5, 2013
Showing with 36 additions and 3 deletions.
  1. +2 −1 .gitignore
  2. +2 −0 Gemfile
  3. +14 −0 Gemfile.lock
  4. +13 −2 app/models/entry.rb
  5. +1 −0 config/initializers/tire.rb
  6. +4 −0 config/initializers/tire_async_index.rb
View
@@ -18,4 +18,5 @@
/public/uploads
.powenv
.env
-.env-tmp
+.env-tmp
+elasticsearch.log
View
@@ -51,6 +51,8 @@ gem 'foreman'
gem 'yajl-ruby', require: nil
gem 'readability_parser'
gem 'lograge'
+gem 'tire'
+gem 'tire_async_index'
# Sidekiq
gem 'sidekiq'
View
@@ -90,6 +90,7 @@ GEM
tzinfo (~> 0.3.37)
addressable (2.3.5)
aggregate (0.2.2)
+ ansi (1.4.3)
arel (4.0.0)
atomic (1.1.14)
autoprefixer-rails (0.8.20130919)
@@ -156,6 +157,7 @@ GEM
gemoji (1.4.0)
github-markdown (0.5.3)
hashie (1.2.0)
+ hashr (0.0.22)
highline (1.6.19)
hike (1.2.3)
honeybadger (1.8.0)
@@ -292,6 +294,16 @@ GEM
atomic
tilt (1.4.1)
timers (1.1.0)
+ tire (0.6.0)
+ activemodel (>= 3.0)
+ activesupport
+ ansi
+ hashr (~> 0.0.19)
+ multi_json (~> 1.3)
+ rake
+ rest-client (~> 1.6)
+ tire_async_index (0.3.0)
+ tire
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
@@ -351,6 +363,8 @@ DEPENDENCIES
stripe
stripe_event
therubyracer
+ tire
+ tire_async_index
uglifier (>= 1.0.3)
unicorn
will_paginate
View
@@ -1,5 +1,7 @@
class Entry < ActiveRecord::Base
-
+ include Tire::Model::Search
+ include Tire::Model::AsyncCallbacks
+
attr_accessor :fully_qualified_url, :read, :starred, :skip_mark_as_unread
belongs_to :feed
@@ -10,8 +12,17 @@ class Entry < ActiveRecord::Base
before_create :cache_public_id, unless: -> { Rails.env.test? }
before_create :create_summary
after_commit :mark_as_unread, on: :create
-
+
validates_uniqueness_of :public_id
+
+
+ def self.search(params, user)
+ tire.search(page: params[:page], per_page: WillPaginate.per_page) do
+ query { string params[:query] } if params[:query].present?
+ filter :or, { terms: { feed_id: user.subscriptions.pluck(:feed_id) } },
+ { ids: { values: user.starred_entries.pluck(:entry_id) } }
+ end
+ end
def entry=(entry)
self.author = entry.author
@@ -0,0 +1 @@
+Tire.configure { logger 'elasticsearch.log' }
@@ -0,0 +1,4 @@
+TireAsyncIndex.configure do |config|
+ config.background_engine :sidekiq
+ config.use_queue :default
+end

0 comments on commit 60876c5

Please sign in to comment.