From 26c78f46cc21c8b6c2e5c6edc77e5219bc82c986 Mon Sep 17 00:00:00 2001 From: manson Date: Thu, 7 Aug 2014 18:45:21 +0800 Subject: [PATCH] update backend search --- app/controllers/admin/announcements_controller.rb | 14 ++++++-------- app/views/admin/announcements/index.html.erb | 7 +------ 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/app/controllers/admin/announcements_controller.rb b/app/controllers/admin/announcements_controller.rb index f3666aa..d3a1296 100644 --- a/app/controllers/admin/announcements_controller.rb +++ b/app/controllers/admin/announcements_controller.rb @@ -15,15 +15,13 @@ class Admin::AnnouncementsController < OrbitAdminController @filter_fields = filter_fields(@categories, @tags) @table_fields = [:status, :category, :title, :start_date, :end_date, :last_modified] - @bulletins = Bulletin.where(:is_preview.in=>[false,nil]).order_by(sort).with_categories(filters("category")).with_tags(filters("tag")).with_status(filters("status")).page(params[:page]).per(10) + @bulletins = Bulletin.where(:is_preview.in=>[false,nil]) + .order_by(sort) + .with_categories(filters("category")) + .with_tags(filters("tag")) + .with_status(filters("status")) - if params[:keywords].present? - key_string = params[:keywords] - key_string = key_string.strip.nil? ? key_string : key_string.strip - keywords = key_string.split(/\s+(?=(?:[^"]*"[^"]*")*[^"]*$)/) - regex = Regexp.union(keywords.map{|word| Regexp.new(".*"+word+".*", "i")}) - @bulletins = @bulletins.any_of({:title=>regex}).page(params[:page]).per(10) - end + @bulletins = search_data(@bulletins,[:title]).page(params[:page]).per(10) if request.xhr? render :partial => "index" diff --git a/app/views/admin/announcements/index.html.erb b/app/views/admin/announcements/index.html.erb index 0c75748..1ad9a26 100644 --- a/app/views/admin/announcements/index.html.erb +++ b/app/views/admin/announcements/index.html.erb @@ -3,9 +3,4 @@ <%= render 'index'%> -<%= render 'layouts/delete_modal', delete_options: @delete_options %> - - \ No newline at end of file +<%= render 'layouts/delete_modal', delete_options: @delete_options %> \ No newline at end of file