diff --git a/config/solr.yml.dist b/config/solr.yml.dist index e9467ec..b0c88c5 100644 --- a/config/solr.yml.dist +++ b/config/solr.yml.dist @@ -6,14 +6,17 @@ development: url: http://0.0.0.0:8982/solr jvm_options: -server -Xmx128M -Xms16M + timeout: 0 production: url: http://127.0.0.1:8983/solr jvm_options: -server -Xmx192M -Xms64M + timeout: 0 test: &TEST url: http://0.0.0.0:8981/solr jvm_options: -server -Xmx128M -Xms16M + timeout: 0 cucumber: <<: *TEST diff --git a/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr.rb b/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr.rb index a64d5fb..3a75756 100644 --- a/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr.rb +++ b/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr.rb @@ -24,19 +24,22 @@ module ActsAsSolr class Post class << self def config - @config ||= YAML::load_file("#{Rails.root}/config/solr.yml")[Rails.env] + return @config if @config + @config = {} + YAML::load_file("#{Rails.root}/config/solr.yml")[Rails.env].each{ |k,v| @config[k.to_sym] = v } + @config end def options - @options ||= credentials.merge( :timeout => config['timeout'] ) + @options ||= credentials.merge config end def credentials - @credentials ||= {:username => config['username'], :password => config['password']} + @credentials ||= {:username => config[:username], :password => config[:password]} end def url(core) - core.nil? ? config['url'] : "#{config['url']}/#{core}" + core.nil? ? config[:url] : "#{config[:url]}/#{core}" end def execute(request, core = nil) diff --git a/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/acts_methods.rb b/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/acts_methods.rb index 25900df..6a6e406 100644 --- a/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/acts_methods.rb +++ b/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/acts_methods.rb @@ -1,3 +1,6 @@ +# a list of models which called acts_as_solr +$solr_indexed_models = [] + module ActsAsSolr #:nodoc: module ActsMethods @@ -165,6 +168,8 @@ module ActsAsSolr #:nodoc: # spatial: Default false. When true, indexes model.local.latitude and model.local.longitude as coordinates. def acts_as_solr(options={}, solr_options={}, &deferred_solr_configuration) + $solr_indexed_models << self + extend ClassMethods include InstanceMethods include CommonMethods @@ -370,4 +375,5 @@ module ActsAsSolr #:nodoc: end end end -end \ No newline at end of file +end + diff --git a/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/class_methods.rb b/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/class_methods.rb index ada9d09..dc74227 100644 --- a/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/class_methods.rb +++ b/vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/class_methods.rb @@ -209,14 +209,15 @@ module ActsAsSolr #:nodoc: # If a finder block is given, it will be called to retrieve the items to index. # This can be very useful for things such as updating based on conditions or # using eager loading for indexed associations. - def rebuild_solr_index(batch_size=100, &finder) + def rebuild_solr_index(batch_size=100, options = {}, &finder) finder ||= lambda { |ar, options| ar.find(:all, options.merge({:order => self.primary_key})) } start_time = Time.now + options[:offset] ||= 0 if batch_size > 0 items_processed = 0 limit = batch_size - offset = 0 + offset = options[:offset] begin iteration_start = Time.now items = finder.call(self, {:limit => limit, :offset => offset}) diff --git a/vendor/plugins/acts_as_solr_reloaded/lib/tasks/solr.rake b/vendor/plugins/acts_as_solr_reloaded/lib/tasks/solr.rake index c942d21..d5a950a 100644 --- a/vendor/plugins/acts_as_solr_reloaded/lib/tasks/solr.rake +++ b/vendor/plugins/acts_as_solr_reloaded/lib/tasks/solr.rake @@ -111,20 +111,15 @@ namespace :solr do task :reindex => :environment do require File.expand_path("#{File.dirname(__FILE__)}/../../config/solr_environment") - includes = env_array_to_constants('ONLY') - if includes.empty? - includes = Dir.glob("#{RAILS_ROOT}/app/models/*.rb").map { |path| File.basename(path, ".rb").camelize.constantize } - end - excludes = env_array_to_constants('EXCEPT') - includes -= excludes - - optimize = env_to_bool('OPTIMIZE', true) - start_server = env_to_bool('START_SERVER', false) - clear_first = env_to_bool('CLEAR', true) - batch_size = ENV['BATCH'].to_i.nonzero? || 300 - debug_output = env_to_bool("DEBUG", false) + optimize = env_to_bool('OPTIMIZE', true) + start_server = env_to_bool('START_SERVER', false) + offset = ENV['OFFSET'].to_i.nonzero? || 0 + clear_first = env_to_bool('CLEAR', offset == 0) + batch_size = ENV['BATCH'].to_i.nonzero? || 300 + debug_output = env_to_bool("DEBUG", false) - RAILS_DEFAULT_LOGGER.level = ActiveSupport::BufferedLogger::INFO unless debug_output + logger = ActiveRecord::Base.logger = Logger.new(STDOUT) + logger.level = ActiveSupport::BufferedLogger::INFO unless debug_output if start_server puts "Starting Solr server..." @@ -138,37 +133,26 @@ namespace :solr do alias_method :solr_optimize, :blank end - models = includes.select { |m| m.respond_to?(:rebuild_solr_index) } - models.each do |model| + $solr_indexed_models.each do |model| if clear_first puts "Clearing index for #{model}..." - ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "#{model.solr_configuration[:type_field]}:#{model}")) - ActsAsSolr::Post.execute(Solr::Request::Commit.new) + #ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "#{model.solr_configuration[:type_field]}:#{model}")) + #ActsAsSolr::Post.execute(Solr::Request::Commit.new) end puts "Rebuilding index for #{model}..." - model.rebuild_solr_index(batch_size) + model.rebuild_solr_index batch_size, :offset => offset end - if models.empty? + if $solr_indexed_models.empty? puts "There were no models to reindex." elsif optimize puts "Optimizing..." models.last.deferred_solr_optimize end - if start_server - puts "Shutting down Solr server..." - Rake::Task["solr:stop"].invoke - end - - end - - def env_array_to_constants(env) - env = ENV[env] || '' - env.split(/\s*,\s*/).map { |m| m.singularize.camelize.constantize }.uniq end def env_to_bool(env, default) -- libgit2 0.21.2