全站搜索

This commit is contained in:
lizanle 2015-11-27 10:40:58 +08:00
parent ee47187a61
commit 7cb39d1754
5 changed files with 13 additions and 9 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1 @@
require 'elasticsearch/rails/tasks/import'