全站搜索

This commit is contained in:
lizanle 2015-11-27 09:52:51 +08:00
parent dcd441a9db
commit ee47187a61
4 changed files with 22 additions and 9 deletions

View File

@ -16,7 +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'
indexes :updated_at, analyzer: 'smartcn',index_options: 'offsets',type:"date"
end
end

View File

@ -39,7 +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'
indexes :updated_on, analyzer: 'smartcn',index_options: 'offsets', type:'date'
end
end
@ -195,12 +195,12 @@ class Project < ActiveRecord::Base
query: query,
type:"most_fields",
operator: "and",
fields: ['name','description^0.5']
fields: ['name']
}
},
sort: {
updated_on:{order: "desc" },
_score:{order: "desc" }
_score:{order: "desc" },
updated_on:{order: "desc" }
},
highlight: {
pre_tags: ['<span class="c_red">'],
@ -1217,13 +1217,19 @@ class Project < ActiveRecord::Base
def create_project_ealasticsearch_index
if self.is_public == 1
self.__elasticsearch__.index_document
end
end
def update_project_ealasticsearch_index
if self.is_public == 1
self.__elasticsearch__.update_document
end
end
def delete_project_ealasticsearch_index
if self.is_public == 1
self.__elasticsearch__.delete_document
end
end

View File

@ -35,7 +35,8 @@ 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'
indexes :last_login_on, analyzer: 'smartcn',index_options: 'offsets',type: 'date'
indexes :id, analyzer: 'smartcn',index_options: 'offsets'
end
end
@ -278,8 +279,8 @@ class User < Principal
}
},
sort:{
last_login_on: {order:"desc"},
_score:{order:"desc"}
_score:{order:"desc"},
last_login_on: {order:"desc"}
},
highlight: {
pre_tags: ['<span class="c_red">'],

View File

@ -73,7 +73,13 @@ module RedmineApp
end
config.after_initialize do
Elasticsearch::Client.new hosts: ['localhost:9200', 'localhost:9201'], retry_on_failure: true,log:true
if RbConfig::CONFIG['target_os'] == 'mswin32'
Elasticsearch::Client.new hosts: ['localhost:9200'], retry_on_failure: true
elsif RbConfig::CONFIG['target_os'] == 'linux' && ["testtrustie11","agent12"].include?(`hostname`)
Elasticsearch::Client.new hosts: ['192.168.80.11:9200','192.168.80.12:9200'], retry_on_failure: true
elsif RbConfig::CONFIG['target_os'] == 'linux' && ["trustie168","trustieserver14","trustieserver16","Trustie18"].include?(`hostname`)
Elasticsearch::Client.new hosts: ['192.168.80.168:9200','192.168.80.14:9200','192.168.80.16:9200','192.168.80.18:9200'], retry_on_failure: true
end
end
if File.exists?(File.join(File.dirname(__FILE__), 'additional_environment.rb'))