From 5d5306dede70c2baaaf702ca1db16cd7b69a2129 Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Sun, 9 Oct 2016 15:05:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E8=AF=BE=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/welcome_controller.rb | 4 ++-- app/models/syllabus.rb | 2 ++ lib/tasks/elasticsearch_batch_op.rake | 9 ++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 1d8f95779..7f13082d2 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -179,7 +179,7 @@ class WelcomeController < ApplicationController content:{} } } - },[User,Course,Attachment,Project,Memo] ).page(params[:page] || 1).per(20).results + },[User,Syllabus,Course,Attachment,Project,Memo] ).page(params[:page] || 1).per(20).results when 'user' @users = User.search(@name).page(params[:page] || 1).per(20) when 'syllabus' @@ -251,7 +251,7 @@ class WelcomeController < ApplicationController content:{} } } - },[User,Course,Attachment,Project,Memo] ).results.total + },[User,Syllabus,Course,Attachment,Project,Memo] ).results.total # search_type = params[:search_type].to_sym unless search_condition.blank? # search_by = params[:search_by] # diff --git a/app/models/syllabus.rb b/app/models/syllabus.rb index 5314f8dbd..b471c0684 100644 --- a/app/models/syllabus.rb +++ b/app/models/syllabus.rb @@ -33,6 +33,8 @@ class Syllabus < ActiveRecord::Base after_create :create_syllabus_ealasticsearch_index before_destroy :delete_syllabus_ealasticsearch_index + scope :indexable,lambda { where(nil) }#用于elastic建索引的scope + scope :like, lambda {|arg| if arg.blank? where(nil) diff --git a/lib/tasks/elasticsearch_batch_op.rake b/lib/tasks/elasticsearch_batch_op.rake index b9933cf75..6693fcf69 100644 --- a/lib/tasks/elasticsearch_batch_op.rake +++ b/lib/tasks/elasticsearch_batch_op.rake @@ -22,6 +22,13 @@ namespace :importer do ENV['BATCH']='1000' Rake::Task["elasticsearch:import:model"].execute end + task :importsyllabus => :environment do + ENV['CLASS']='Syllabus' + ENV['SCOPE']='indexable' + ENV['FORCE']='y' + ENV['BATCH']='1000' + Rake::Task["elasticsearch:import:model"].execute + end task :importattachment => :environment do ENV['CLASS']='Attachment' ENV['SCOPE']='indexable' @@ -38,5 +45,5 @@ namespace :importer do end desc "Run all tasks" - task :all => [:importuser,:importproject,:importcourse,:importattachment,:importmemo] + task :all => [:importuser,:importproject,:importsyllabus,:importcourse,:importattachment,:importmemo] end \ No newline at end of file