搜索课程

This commit is contained in:
yuanke 2016-10-09 11:27:35 +08:00
parent cd34388909
commit f380c64653
1 changed files with 27 additions and 0 deletions

View File

@ -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(
{