全站搜索
This commit is contained in:
parent
4efb660214
commit
dcd441a9db
|
@ -160,7 +160,8 @@ class WelcomeController < ApplicationController
|
|||
multi_match: {
|
||||
query: @name,
|
||||
type:"most_fields",
|
||||
fields: ['login^5', 'firstname','lastname','name^5','description','filename^5']
|
||||
operator: "or",
|
||||
fields: ['login', 'firstname','lastname','name','description^0.5','filename']
|
||||
}
|
||||
},
|
||||
highlight: {
|
||||
|
@ -190,7 +191,8 @@ class WelcomeController < ApplicationController
|
|||
multi_match: {
|
||||
query: @name,
|
||||
type:"most_fields",
|
||||
fields: ['login^5', 'firstname','lastname','name^5','description','filename^5']
|
||||
operator: "or",
|
||||
fields: ['login', 'firstname','lastname','name','description^0.5','filename']
|
||||
}
|
||||
},
|
||||
highlight: {
|
||||
|
@ -219,7 +221,8 @@ class WelcomeController < ApplicationController
|
|||
multi_match: {
|
||||
query: @name,
|
||||
type:"most_fields",
|
||||
fields: ['login^5', 'firstname','lastname','name^5','description','filename^5']
|
||||
operator: "or",
|
||||
fields: ['login', 'firstname','lastname','name','description^0.5','filename']
|
||||
}
|
||||
},
|
||||
highlight: {
|
||||
|
|
|
@ -46,6 +46,7 @@ class Attachment < ActiveRecord::Base
|
|||
settings index: { number_of_shards: 1 } do
|
||||
mappings dynamic: 'false' do
|
||||
indexes :filename, analyzer: 'smartcn',index_options: 'offsets'
|
||||
indexes :downloads, analyzer: 'smartcn',index_options: 'offsets'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -109,9 +110,15 @@ class Attachment < ActiveRecord::Base
|
|||
query: {
|
||||
multi_match: {
|
||||
query: query,
|
||||
type:"most_fields",
|
||||
operator: "or",
|
||||
fields: ['filename']
|
||||
}
|
||||
},
|
||||
sort:{
|
||||
downloads: {order:"desc"},
|
||||
_score:{order:"desc"}
|
||||
},
|
||||
highlight: {
|
||||
pre_tags: ['<span class="c_red">'],
|
||||
post_tags: ['</span>'],
|
||||
|
@ -625,4 +632,4 @@ end
|
|||
#暂时只做公开课程/项目里的公开资源 和其他的公开资源
|
||||
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
|
||||
'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
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
class Board < ActiveRecord::Base
|
||||
include Redmine::SafeAttributes
|
||||
belongs_to :project
|
||||
belongs_to :project,:touch => true
|
||||
belongs_to :course
|
||||
has_many :topics, :class_name => 'Message', :conditions => "#{Message.table_name}.parent_id IS NULL", :order => "#{Message.table_name}.created_on DESC"
|
||||
has_many :messages, :dependent => :destroy, :order => "#{Message.table_name}.created_on DESC"
|
||||
|
|
|
@ -16,6 +16,7 @@ class Course < ActiveRecord::Base
|
|||
mappings dynamic: 'false' do
|
||||
indexes :name, analyzer: 'smartcn',index_options: 'offsets'
|
||||
indexes :description, analyzer: 'smartcn',index_options: 'offsets'
|
||||
indexes :updated_at, analyzer: 'smartcn',index_options: 'offsets'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -115,9 +116,15 @@ class Course < ActiveRecord::Base
|
|||
query: {
|
||||
multi_match: {
|
||||
query: query,
|
||||
fields: ['name', 'description']
|
||||
type:"most_fields",
|
||||
operator: "or",
|
||||
fields: ['name', 'description^0.5']
|
||||
}
|
||||
},
|
||||
sort: {
|
||||
updated_at:{order:"desc"},
|
||||
_score:{order: "desc" }
|
||||
},
|
||||
highlight: {
|
||||
pre_tags: ['<span class="c_red">'],
|
||||
post_tags: ['</span>'],
|
||||
|
@ -405,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.import
|
||||
Course.where('is_public = 1').import :force=>true
|
||||
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
class Document < ActiveRecord::Base
|
||||
include Redmine::SafeAttributes
|
||||
belongs_to :project
|
||||
belongs_to :project,:touch=>true
|
||||
belongs_to :user
|
||||
belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id"
|
||||
include UserScoreHelper
|
||||
|
|
|
@ -19,7 +19,7 @@ class Issue < ActiveRecord::Base
|
|||
include Redmine::SafeAttributes
|
||||
include Redmine::Utils::DateCalculation
|
||||
include UserScoreHelper
|
||||
belongs_to :project
|
||||
belongs_to :project,:touch=> true
|
||||
belongs_to :tracker
|
||||
belongs_to :status, :class_name => 'IssueStatus', :foreign_key => 'status_id'
|
||||
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
|
||||
|
|
|
@ -21,7 +21,8 @@ class JournalsForMessage < ActiveRecord::Base
|
|||
after_destroy :delete_kindeditor_assets
|
||||
belongs_to :project,
|
||||
:foreign_key => 'jour_id',
|
||||
:conditions => "#{self.table_name}.jour_type = 'Project' "
|
||||
:conditions => "#{self.table_name}.jour_type = 'Project' ",:touch => true
|
||||
|
||||
belongs_to :course,
|
||||
:foreign_key => 'jour_id'
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ class Message < ActiveRecord::Base
|
|||
include UserScoreHelper
|
||||
include ApplicationHelper
|
||||
has_many_kindeditor_assets :assets, :dependent => :destroy
|
||||
belongs_to :board
|
||||
belongs_to :board,:touch => true
|
||||
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
|
||||
has_many :praise_tread, as: :praise_tread_object, dependent: :destroy
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
class News < ActiveRecord::Base
|
||||
include Redmine::SafeAttributes
|
||||
belongs_to :project
|
||||
belongs_to :project,:touch => true
|
||||
include ApplicationHelper
|
||||
has_many_kindeditor_assets :assets, :dependent => :destroy
|
||||
#added by nwb
|
||||
|
|
|
@ -39,6 +39,7 @@ class Project < ActiveRecord::Base
|
|||
mappings dynamic: 'false' do
|
||||
indexes :name, analyzer: 'smartcn',index_options: 'offsets'
|
||||
indexes :description, analyzer: 'smartcn',index_options: 'offsets'
|
||||
indexes :updated_on, analyzer: 'smartcn',index_options: 'offsets'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -192,9 +193,15 @@ class Project < ActiveRecord::Base
|
|||
query: {
|
||||
multi_match: {
|
||||
query: query,
|
||||
fields: ['name','description']
|
||||
type:"most_fields",
|
||||
operator: "and",
|
||||
fields: ['name','description^0.5']
|
||||
}
|
||||
},
|
||||
sort: {
|
||||
updated_on:{order: "desc" },
|
||||
_score:{order: "desc" }
|
||||
},
|
||||
highlight: {
|
||||
pre_tags: ['<span class="c_red">'],
|
||||
post_tags: ['</span>'],
|
||||
|
@ -1222,5 +1229,5 @@ class Project < ActiveRecord::Base
|
|||
|
||||
end
|
||||
|
||||
Project.import
|
||||
Project.where('is_public = 1').import :force=>true
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
class ProjectTags < ActiveRecord::Base
|
||||
attr_accessible :description, :project_id, :tag_id, :user_id
|
||||
####################################################################################################添加代码
|
||||
belongs_to :project
|
||||
belongs_to :project,:touch => true
|
||||
belongs_to :tag
|
||||
belongs_to :user
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ class User < Principal
|
|||
indexes :login, analyzer: 'smartcn',index_options: 'offsets'
|
||||
indexes :firstname, analyzer: 'smartcn',index_options: 'offsets'
|
||||
indexes :lastname, analyzer: 'smartcn',index_options: 'offsets'
|
||||
indexes :last_login_on, analyzer: 'smartcn',index_options: 'offsets'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -271,9 +272,15 @@ class User < Principal
|
|||
query: {
|
||||
multi_match: {
|
||||
query: query,
|
||||
type:"most_fields",
|
||||
operator: "or",
|
||||
fields: ['login', 'firstname','lastname']
|
||||
}
|
||||
},
|
||||
sort:{
|
||||
last_login_on: {order:"desc"},
|
||||
_score:{order:"desc"}
|
||||
},
|
||||
highlight: {
|
||||
pre_tags: ['<span class="c_red">'],
|
||||
post_tags: ['</span>'],
|
||||
|
@ -1208,4 +1215,4 @@ end
|
|||
|
||||
# Index all article records from the DB to Elasticsearch
|
||||
# 匿名用户 角色 和 管理员角色不能被索引
|
||||
User.where('id not in (2,4)').import
|
||||
User.where('id not in (2,4)').import :force=>true
|
||||
|
|
|
@ -2,7 +2,7 @@ require File.expand_path('../boot', __FILE__)
|
|||
|
||||
require 'rails/all'
|
||||
require 'sprockets/railtie'
|
||||
|
||||
require 'elasticsearch/model'
|
||||
if defined?(Bundler)
|
||||
# If you precompile assets before deploying to production, use this line
|
||||
Bundler.require(*Rails.groups(:assets => %w(development test)))
|
||||
|
@ -73,6 +73,7 @@ module RedmineApp
|
|||
end
|
||||
|
||||
config.after_initialize do
|
||||
Elasticsearch::Client.new hosts: ['localhost:9200', 'localhost:9201'], retry_on_failure: true,log:true
|
||||
end
|
||||
|
||||
if File.exists?(File.join(File.dirname(__FILE__), 'additional_environment.rb'))
|
||||
|
|
Loading…
Reference in New Issue