diff --git a/app/models/attachment.rb b/app/models/attachment.rb index 3cb2d9057..dea4e404e 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -104,6 +104,9 @@ class Attachment < ActiveRecord::Base " LEFT JOIN #{News.table_name} ON #{Attachment.table_name}.container_type='News' AND (#{News.table_name}.project_id in "+self.public_project_id + " OR #{News.table_name}.course_id in " + self.public_course_id + ")" + " LEFT JOIN #{HomeworkAttach.table_name} ON #{Attachment.table_name}.container_type='HomeworkAttach' AND #{HomeworkAttach.table_name}.bid_id in "+self.public_bid_id) } + scope :indexable,lambda { where('is_public = 1 and ((container_type in ("Principal")) ' + + 'or (container_type = "Course" and container_id in( SELECT `courses`.id FROM `courses` WHERE (courses.status <> 9 AND courses.is_public = 1)) )'+ + 'or (container_type = "Project" and container_id in(SELECT `projects`.id FROM `projects` WHERE (projects.status <> 9 AND projects.is_public = 1) ))' +')')} #用于elastic建索引的scope def self.search(query) __elasticsearch__.search( { @@ -630,6 +633,6 @@ end # Index all article records from the DB to Elasticsearch #暂时只做公开课程/项目里的公开资源 和其他的公开资源 -Attachment.where('is_public = 1 and ((container_type in ("Principal")) ' + - 'or (container_type = "Course" and container_id in( SELECT `courses`.id FROM `courses` WHERE (courses.status <> 9 AND courses.is_public = 1)) )'+ - 'or (container_type = "Project" and container_id in(SELECT `projects`.id FROM `projects` WHERE (projects.status <> 9 AND projects.is_public = 1) ))' +')').import :force=>true +#Attachment.where('is_public = 1 and ((container_type in ("Principal")) ' + +# 'or (container_type = "Course" and container_id in( SELECT `courses`.id FROM `courses` WHERE (courses.status <> 9 AND courses.is_public = 1)) )'+ +# 'or (container_type = "Project" and container_id in(SELECT `projects`.id FROM `projects` WHERE (projects.status <> 9 AND projects.is_public = 1) ))' +')').import :force=>true diff --git a/app/models/course.rb b/app/models/course.rb index e73257033..8f7c990ab 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -109,7 +109,7 @@ class Course < ActiveRecord::Base where(" LOWER(name) LIKE :p ", :p => pattern) end } - + scope :indexable,lambda { where('is_public = 1') } def self.search(query) __elasticsearch__.search( { @@ -412,6 +412,6 @@ end # body: { settings: Course.settings.to_hash, mappings: Course.mappings.to_hash } # Index all article records from the DB to Elasticsearch -Course.where('is_public = 1').import :force=>true +#Course.where('is_public = 1').import :force=>true diff --git a/app/models/project.rb b/app/models/project.rb index 0453f1164..034873596 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -186,7 +186,7 @@ class Project < ActiveRecord::Base } scope :project_entities, -> { where(project_type: ProjectType_project) } scope :course_entities, -> { where(project_type: ProjectType_course) } - + scope :indexable,lambda { where('is_public = 1')} #用于elastic建索引的scope def self.search(query) __elasticsearch__.search( { @@ -1235,5 +1235,5 @@ class Project < ActiveRecord::Base end -Project.where('is_public = 1').import :force=>true +#Project.where('is_public = 1').import :force=>true diff --git a/app/models/user.rb b/app/models/user.rb index 15578f6db..bf2bca6db 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -249,7 +249,7 @@ class User < Principal where("#{User.table_name}.id NOT IN (SELECT gu.user_id FROM #{table_name_prefix}groups_users#{table_name_suffix} gu WHERE gu.group_id = ?)", group_id) } scope :sorted, lambda { order(*User.fields_for_order_statement)} - + scope :indexable,lambda { where('id not in (2,4)')} #用于elastic建索引的scope,id为2是匿名用户,4是管理员,不能被索引 scope :like, lambda {|arg, type| if arg.blank? where(nil) @@ -1216,4 +1216,4 @@ end # Index all article records from the DB to Elasticsearch # 匿名用户 角色 和 管理员角色不能被索引 -User.where('id not in (2,4)').import :force=>true +#User.where('id not in (2,4)').import :force=>true diff --git a/lib/tasks/elasticsearch.rake b/lib/tasks/elasticsearch.rake new file mode 100644 index 000000000..1242abc60 --- /dev/null +++ b/lib/tasks/elasticsearch.rake @@ -0,0 +1 @@ +require 'elasticsearch/rails/tasks/import' \ No newline at end of file