diff --git a/app/controllers/panel/announcement/front_end/bulletins_controller.rb b/app/controllers/panel/announcement/front_end/bulletins_controller.rb index d2fee70..bfe2106 100644 --- a/app/controllers/panel/announcement/front_end/bulletins_controller.rb +++ b/app/controllers/panel/announcement/front_end/bulletins_controller.rb @@ -12,8 +12,13 @@ class Panel::Announcement::FrontEnd::BulletinsController < OrbitWidgetController if params[:search_query] == "" @bulletins = get_bulletins_for_index else - @search = Bulletin.tire.search "#{params[:search_query]}" - search_result = @search.collect{|result| result.id} + key_string = params[:search_query] + 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) end diff --git a/app/models/bulletin.rb b/app/models/bulletin.rb index 843d597..ffb5cc8 100644 --- a/app/models/bulletin.rb +++ b/app/models/bulletin.rb @@ -13,8 +13,8 @@ class Bulletin include OrbitModel::TimeFrame include OrbitTag::Taggable - include Tire::Model::Search - include Tire::Model::Callbacks + # include Tire::Model::Search + # include Tire::Model::Callbacks is_impressionable :counter_cache => { :column_name => :view_count } @@ -44,9 +44,9 @@ class Bulletin validates :title, :at_least_one => true - def to_indexed_json - self.to_json - end + # def to_indexed_json + # self.to_json + # end # search_in :title, :subtitle, :text