Remove elasticsearch

This commit is contained in:
Manson Wang 2014-03-27 11:27:43 +08:00
parent 5bab384195
commit 45d9bbc342
2 changed files with 12 additions and 7 deletions

View File

@ -12,8 +12,13 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController
if params[:search_query] == "" if params[:search_query] == ""
@bulletins = get_bulletins_for_index @bulletins = get_bulletins_for_index
else else
@search = Bulletin.tire.search "#{params[:search_query]}" key_string = params[:search_query]
search_result = @search.collect{|result| result.id} keywords = key_string.split(/\s+(?=(?:[^"]*"[^"]*")*[^"]*$)/)
regex = Regexp.union(keywords.map{|word| Regexp.new(".*"+word+".*", "i")})
query = ["title","subtitle","text"].map{|f| {f.to_sym => regex} }
res = Bulletin.any_of(query)
search_result = res.collect{|result| result.id}
@bulletins = Bulletin.all.available_for_lang(I18n.locale).can_display.any_in(_id:search_result).page( params[:page_main]).per(@page_num) @bulletins = Bulletin.all.available_for_lang(I18n.locale).can_display.any_in(_id:search_result).page( params[:page_main]).per(@page_num)
end end

View File

@ -13,8 +13,8 @@ class Bulletin
include OrbitModel::TimeFrame include OrbitModel::TimeFrame
include OrbitTag::Taggable include OrbitTag::Taggable
include Tire::Model::Search # include Tire::Model::Search
include Tire::Model::Callbacks # include Tire::Model::Callbacks
is_impressionable :counter_cache => { :column_name => :view_count } is_impressionable :counter_cache => { :column_name => :view_count }
@ -44,9 +44,9 @@ class Bulletin
validates :title, :at_least_one => true validates :title, :at_least_one => true
def to_indexed_json # def to_indexed_json
self.to_json # self.to_json
end # end
# search_in :title, :subtitle, :text # search_in :title, :subtitle, :text