From f380c64653707cbde25d6579c84907a9779c6215 Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Sun, 9 Oct 2016 11:27:35 +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/models/syllabus.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/app/models/syllabus.rb b/app/models/syllabus.rb index 2f69ce5c4..b046ce2cd 100644 --- a/app/models/syllabus.rb +++ b/app/models/syllabus.rb @@ -17,6 +17,10 @@ class Syllabus < ActiveRecord::Base validates :title, :user_id, presence: true + after_update :update_syllabus_ealasticsearch_index + after_create :create_syllabus_ealasticsearch_index + before_destroy :delete_syllabus_ealasticsearch_index + scope :like, lambda {|arg| if arg.blank? where(nil) @@ -58,6 +62,29 @@ class Syllabus < ActiveRecord::Base jfm end + def create_syllabus_ealasticsearch_index + return if Rails.env.development? + self.__elasticsearch__.index_document + end + + def update_syllabus_ealasticsearch_index + return if Rails.env.development? + begin + self.__elasticsearch__.update_document + rescue => e + self.__elasticsearch__.index_document + end + end + + def delete_syllabus_ealasticsearch_index + return if Rails.env.development? + begin + self.__elasticsearch__.delete_document + rescue => e + + end + end + def self.search(query) __elasticsearch__.search( {