课程被删除后不能被搜索

This commit is contained in:
lizanle 2015-12-10 10:00:14 +08:00
parent 916d99be82
commit 7f866a0b3a
1 changed files with 3 additions and 3 deletions

View File

@ -115,7 +115,7 @@ class Course < ActiveRecord::Base
where(" LOWER(name) LIKE :p ", :p => pattern)
end
}
scope :indexable,lambda { where('is_public = 1') }
scope :indexable,lambda { where('is_public = 1 and is_delete = 0') }
def self.search(query)
__elasticsearch__.search(
{
@ -400,12 +400,12 @@ class Course < ActiveRecord::Base
# __elasticsearch__.delete_document
# end
def create_course_ealasticsearch_index
if self.is_public == 1
if self.is_public == 1 and self.is_delete == 0 #公开 和 没有被删除的课程才被索引
self.__elasticsearch__.index_document
end
end
def update_course_ealasticsearch_index
if self.is_public == 1 #如果是初次更新成为公开的情况,会报错,那么这条记录尚未被索引过。没有报错就是更新的其他属性
if self.is_public == 1 and self.is_delete == 0 #如果是初次更新成为公开或者恢复被删除的情况,会报错,那么这条记录尚未被索引过。没有报错就是更新的其他属性
begin
self.__elasticsearch__.update_document
rescue => e