2014-02-03 12:08:41 +00:00
|
|
|
$LOAD_PATH << './lib'
|
|
|
|
require 'rubygems'
|
|
|
|
|
|
|
|
namespace :searchindex do
|
2015-05-07 09:49:46 +00:00
|
|
|
task :drop, [:opts] => :environment do |_t, _args|
|
2014-02-03 12:08:41 +00:00
|
|
|
|
|
|
|
# drop indexes
|
2015-04-27 13:20:16 +00:00
|
|
|
puts 'drop indexes...'
|
2014-02-03 12:08:41 +00:00
|
|
|
SearchIndexBackend.index(
|
2015-04-27 13:42:53 +00:00
|
|
|
action: 'delete',
|
2014-02-03 12:08:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2015-05-07 09:49:46 +00:00
|
|
|
task :create, [:opts] => :environment do |_t, _args|
|
2014-02-03 12:08:41 +00:00
|
|
|
|
|
|
|
# create indexes
|
2015-04-27 13:20:16 +00:00
|
|
|
puts 'create indexes...'
|
2014-02-03 12:08:41 +00:00
|
|
|
SearchIndexBackend.index(
|
2015-04-27 13:42:53 +00:00
|
|
|
action: 'create',
|
|
|
|
data: {
|
|
|
|
mappings: {
|
|
|
|
Ticket: {
|
2016-09-09 21:10:27 +00:00
|
|
|
_source: { excludes: [ 'article.attachment' ] },
|
2015-04-27 13:42:53 +00:00
|
|
|
properties: {
|
2016-09-09 21:10:27 +00:00
|
|
|
article: {
|
2015-04-27 13:42:53 +00:00
|
|
|
type: 'nested',
|
2016-09-09 21:10:27 +00:00
|
|
|
include_in_parent: true,
|
2015-04-27 13:42:53 +00:00
|
|
|
properties: {
|
2016-09-09 21:10:27 +00:00
|
|
|
attachment: {
|
2015-04-27 13:42:53 +00:00
|
|
|
type: 'attachment',
|
2014-02-03 12:08:41 +00:00
|
|
|
}
|
2014-04-28 15:30:06 +00:00
|
|
|
}
|
2014-02-03 12:08:41 +00:00
|
|
|
}
|
2014-04-28 15:30:06 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-03 12:08:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2015-05-07 09:49:46 +00:00
|
|
|
task :reload, [:opts] => :environment do |_t, _args|
|
2014-02-03 12:08:41 +00:00
|
|
|
|
2015-04-27 13:20:16 +00:00
|
|
|
puts 'reload data...'
|
2017-10-01 12:31:29 +00:00
|
|
|
Models.searchable.each do |model_class|
|
2015-08-16 09:30:31 +00:00
|
|
|
puts " reload #{model_class}"
|
2015-08-16 09:33:16 +00:00
|
|
|
started_at = Time.zone.now
|
|
|
|
puts " - started at #{started_at}"
|
2015-08-16 09:30:31 +00:00
|
|
|
model_class.search_index_reload
|
2015-08-16 09:33:16 +00:00
|
|
|
took = Time.zone.now - started_at
|
|
|
|
puts " - took #{took.to_i} seconds"
|
2017-10-01 12:31:29 +00:00
|
|
|
end
|
2014-02-03 12:08:41 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2015-05-07 09:49:46 +00:00
|
|
|
task :rebuild, [:opts] => :environment do |_t, _args|
|
2014-02-03 12:08:41 +00:00
|
|
|
|
2015-04-27 13:20:16 +00:00
|
|
|
Rake::Task['searchindex:drop'].execute
|
|
|
|
Rake::Task['searchindex:create'].execute
|
|
|
|
Rake::Task['searchindex:reload'].execute
|
2014-02-03 12:08:41 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
end
|