全站搜索

at_guange
lizanle 10 years ago
parent ee47187a61
commit 7cb39d1754

@ -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 #{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) " 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) def self.search(query)
__elasticsearch__.search( __elasticsearch__.search(
{ {
@ -630,6 +633,6 @@ end
# Index all article records from the DB to Elasticsearch # Index all article records from the DB to Elasticsearch
#暂时只做公开课程/项目里的公开资源 和其他的公开资源 #暂时只做公开课程/项目里的公开资源 和其他的公开资源
Attachment.where('is_public = 1 and ((container_type in ("Principal")) ' + #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 = "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 # '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

@ -109,7 +109,7 @@ class Course < ActiveRecord::Base
where(" LOWER(name) LIKE :p ", :p => pattern) where(" LOWER(name) LIKE :p ", :p => pattern)
end end
} }
scope :indexable,lambda { where('is_public = 1') }
def self.search(query) def self.search(query)
__elasticsearch__.search( __elasticsearch__.search(
{ {
@ -412,6 +412,6 @@ end
# body: { settings: Course.settings.to_hash, mappings: Course.mappings.to_hash } # body: { settings: Course.settings.to_hash, mappings: Course.mappings.to_hash }
# Index all article records from the DB to Elasticsearch # 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

@ -186,7 +186,7 @@ class Project < ActiveRecord::Base
} }
scope :project_entities, -> { where(project_type: ProjectType_project) } scope :project_entities, -> { where(project_type: ProjectType_project) }
scope :course_entities, -> { where(project_type: ProjectType_course) } scope :course_entities, -> { where(project_type: ProjectType_course) }
scope :indexable,lambda { where('is_public = 1')} #用于elastic建索引的scope
def self.search(query) def self.search(query)
__elasticsearch__.search( __elasticsearch__.search(
{ {
@ -1235,5 +1235,5 @@ class Project < ActiveRecord::Base
end end
Project.where('is_public = 1').import :force=>true #Project.where('is_public = 1').import :force=>true

@ -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) 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 :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| scope :like, lambda {|arg, type|
if arg.blank? if arg.blank?
where(nil) where(nil)
@ -1216,4 +1216,4 @@ end
# Index all article records from the DB to Elasticsearch # 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

@ -0,0 +1 @@
require 'elasticsearch/rails/tasks/import'
Loading…
Cancel
Save