2021-06-01 12:20:20 +00:00
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
2014-02-03 12:08:41 +00:00
$LOAD_PATH << './lib'
require 'rubygems'
namespace :searchindex do
2020-11-10 07:47:16 +00:00
task :drop , [ :opts ] = > % i [ environment searchindex : configured searchindex : version_supported ] do | _t , _args |
2019-06-20 10:45:27 +00:00
print 'drop indexes...'
2014-02-03 12:08:41 +00:00
# drop indexes
2021-02-01 10:36:53 +00:00
SearchIndexBackend . drop_index
2021-01-27 09:58:35 +00:00
2017-12-15 13:58:41 +00:00
puts 'done'
2014-02-03 12:08:41 +00:00
2017-12-15 13:58:41 +00:00
Rake :: Task [ 'searchindex:drop_pipeline' ] . execute
2014-02-03 12:08:41 +00:00
end
2020-11-10 07:47:16 +00:00
task :create , [ :opts ] = > % i [ environment searchindex : configured searchindex : version_supported ] do | _t , _args |
2017-12-15 13:58:41 +00:00
print 'create indexes...'
2014-02-03 12:08:41 +00:00
2021-02-01 10:36:53 +00:00
SearchIndexBackend . create_index
2017-12-15 13:58:41 +00:00
2018-07-18 14:00:06 +00:00
puts 'done'
2017-12-15 13:58:41 +00:00
Rake :: Task [ 'searchindex:create_pipeline' ] . execute
end
2020-11-10 07:47:16 +00:00
task :create_pipeline , [ :opts ] = > % i [ environment searchindex : configured searchindex : version_supported ] do | _t , _args |
2021-02-01 10:36:53 +00:00
print 'create pipeline (pipeline)... '
2017-12-04 00:24:58 +00:00
2021-02-01 10:36:53 +00:00
SearchIndexBackend . create_pipeline
2021-01-27 09:58:35 +00:00
2017-12-15 13:58:41 +00:00
puts 'done'
end
2020-11-10 07:47:16 +00:00
task :drop_pipeline , [ :opts ] = > % i [ environment searchindex : configured searchindex : version_supported ] do | _t , _args |
2021-02-01 10:36:53 +00:00
print 'delete pipeline (pipeline)... '
2017-12-15 13:58:41 +00:00
2021-02-01 10:36:53 +00:00
SearchIndexBackend . drop_pipeline
2018-10-09 06:17:41 +00:00
2017-12-15 13:58:41 +00:00
puts 'done'
2014-02-03 12:08:41 +00:00
end
2020-11-10 07:47:16 +00:00
task :reload , [ :opts ] = > % i [ environment searchindex : configured searchindex : version_supported ] do | _t , _args |
2015-04-27 13:20:16 +00:00
puts 'reload data...'
2018-10-03 06:23:22 +00:00
Models . indexable . 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
2020-11-10 07:47:16 +00:00
task :refresh , [ :opts ] = > % i [ environment searchindex : configured searchindex : version_supported ] do | _t , _args |
2019-09-24 13:04:42 +00:00
print 'refresh all indexes...'
SearchIndexBackend . refresh
end
2020-11-10 07:47:16 +00:00
task :rebuild , [ :opts ] = > % i [ environment searchindex : configured searchindex : version_supported ] do | _t , _args |
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
2020-02-18 14:49:52 +00:00
task :version_supported , [ :opts ] = > :environment do | _t , _args |
2021-02-01 10:36:53 +00:00
next if SearchIndexBackend . version_supported?
2020-02-18 14:49:52 +00:00
2021-02-01 10:36:53 +00:00
abort " Your Elasticsearch version is not supported! Please update your version to a greater equal than 6.5.0 (Your current version: #{ SearchIndexBackend . version } ). "
2020-11-10 07:47:16 +00:00
end
task :configured , [ :opts ] = > :environment do | _t , _args |
2021-02-01 10:36:53 +00:00
next if SearchIndexBackend . configured?
2020-11-10 07:47:16 +00:00
abort " You have not configured Elasticsearch (Setting.get('es_url')). "
2020-02-18 14:49:52 +00:00
end
2014-02-03 12:08:41 +00:00
end