Commit df397df08eff0ca190a49386e05adbc2068ed51b
1 parent
e305aa61
Exists in
master
and in
23 other branches
Remove timeout and fix solr:reindex
Showing
5 changed files
with
33 additions
and
36 deletions
Show diff stats
config/solr.yml.dist
| ... | ... | @@ -6,14 +6,17 @@ |
| 6 | 6 | development: |
| 7 | 7 | url: http://0.0.0.0:8982/solr |
| 8 | 8 | jvm_options: -server -Xmx128M -Xms16M |
| 9 | + timeout: 0 | |
| 9 | 10 | |
| 10 | 11 | production: |
| 11 | 12 | url: http://127.0.0.1:8983/solr |
| 12 | 13 | jvm_options: -server -Xmx192M -Xms64M |
| 14 | + timeout: 0 | |
| 13 | 15 | |
| 14 | 16 | test: &TEST |
| 15 | 17 | url: http://0.0.0.0:8981/solr |
| 16 | 18 | jvm_options: -server -Xmx128M -Xms16M |
| 19 | + timeout: 0 | |
| 17 | 20 | |
| 18 | 21 | cucumber: |
| 19 | 22 | <<: *TEST | ... | ... |
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr.rb
| ... | ... | @@ -24,19 +24,22 @@ module ActsAsSolr |
| 24 | 24 | class Post |
| 25 | 25 | class << self |
| 26 | 26 | def config |
| 27 | - @config ||= YAML::load_file("#{Rails.root}/config/solr.yml")[Rails.env] | |
| 27 | + return @config if @config | |
| 28 | + @config = {} | |
| 29 | + YAML::load_file("#{Rails.root}/config/solr.yml")[Rails.env].each{ |k,v| @config[k.to_sym] = v } | |
| 30 | + @config | |
| 28 | 31 | end |
| 29 | 32 | |
| 30 | 33 | def options |
| 31 | - @options ||= credentials.merge( :timeout => config['timeout'] ) | |
| 34 | + @options ||= credentials.merge config | |
| 32 | 35 | end |
| 33 | 36 | |
| 34 | 37 | def credentials |
| 35 | - @credentials ||= {:username => config['username'], :password => config['password']} | |
| 38 | + @credentials ||= {:username => config[:username], :password => config[:password]} | |
| 36 | 39 | end |
| 37 | 40 | |
| 38 | 41 | def url(core) |
| 39 | - core.nil? ? config['url'] : "#{config['url']}/#{core}" | |
| 42 | + core.nil? ? config[:url] : "#{config[:url]}/#{core}" | |
| 40 | 43 | end |
| 41 | 44 | |
| 42 | 45 | def execute(request, core = nil) | ... | ... |
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/acts_methods.rb
| 1 | +# a list of models which called acts_as_solr | |
| 2 | +$solr_indexed_models = [] | |
| 3 | + | |
| 1 | 4 | module ActsAsSolr #:nodoc: |
| 2 | 5 | |
| 3 | 6 | module ActsMethods |
| ... | ... | @@ -165,6 +168,8 @@ module ActsAsSolr #:nodoc: |
| 165 | 168 | # spatial: Default false. When true, indexes model.local.latitude and model.local.longitude as coordinates. |
| 166 | 169 | def acts_as_solr(options={}, solr_options={}, &deferred_solr_configuration) |
| 167 | 170 | |
| 171 | + $solr_indexed_models << self | |
| 172 | + | |
| 168 | 173 | extend ClassMethods |
| 169 | 174 | include InstanceMethods |
| 170 | 175 | include CommonMethods |
| ... | ... | @@ -370,4 +375,5 @@ module ActsAsSolr #:nodoc: |
| 370 | 375 | end |
| 371 | 376 | end |
| 372 | 377 | end |
| 373 | -end | |
| 374 | 378 | \ No newline at end of file |
| 379 | +end | |
| 380 | + | ... | ... |
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr/class_methods.rb
| ... | ... | @@ -209,14 +209,15 @@ module ActsAsSolr #:nodoc: |
| 209 | 209 | # If a finder block is given, it will be called to retrieve the items to index. |
| 210 | 210 | # This can be very useful for things such as updating based on conditions or |
| 211 | 211 | # using eager loading for indexed associations. |
| 212 | - def rebuild_solr_index(batch_size=100, &finder) | |
| 212 | + def rebuild_solr_index(batch_size=100, options = {}, &finder) | |
| 213 | 213 | finder ||= lambda { |ar, options| ar.find(:all, options.merge({:order => self.primary_key})) } |
| 214 | 214 | start_time = Time.now |
| 215 | + options[:offset] ||= 0 | |
| 215 | 216 | |
| 216 | 217 | if batch_size > 0 |
| 217 | 218 | items_processed = 0 |
| 218 | 219 | limit = batch_size |
| 219 | - offset = 0 | |
| 220 | + offset = options[:offset] | |
| 220 | 221 | begin |
| 221 | 222 | iteration_start = Time.now |
| 222 | 223 | items = finder.call(self, {:limit => limit, :offset => offset}) | ... | ... |
vendor/plugins/acts_as_solr_reloaded/lib/tasks/solr.rake
| ... | ... | @@ -111,20 +111,15 @@ namespace :solr do |
| 111 | 111 | task :reindex => :environment do |
| 112 | 112 | require File.expand_path("#{File.dirname(__FILE__)}/../../config/solr_environment") |
| 113 | 113 | |
| 114 | - includes = env_array_to_constants('ONLY') | |
| 115 | - if includes.empty? | |
| 116 | - includes = Dir.glob("#{RAILS_ROOT}/app/models/*.rb").map { |path| File.basename(path, ".rb").camelize.constantize } | |
| 117 | - end | |
| 118 | - excludes = env_array_to_constants('EXCEPT') | |
| 119 | - includes -= excludes | |
| 120 | - | |
| 121 | - optimize = env_to_bool('OPTIMIZE', true) | |
| 122 | - start_server = env_to_bool('START_SERVER', false) | |
| 123 | - clear_first = env_to_bool('CLEAR', true) | |
| 124 | - batch_size = ENV['BATCH'].to_i.nonzero? || 300 | |
| 125 | - debug_output = env_to_bool("DEBUG", false) | |
| 114 | + optimize = env_to_bool('OPTIMIZE', true) | |
| 115 | + start_server = env_to_bool('START_SERVER', false) | |
| 116 | + offset = ENV['OFFSET'].to_i.nonzero? || 0 | |
| 117 | + clear_first = env_to_bool('CLEAR', offset == 0) | |
| 118 | + batch_size = ENV['BATCH'].to_i.nonzero? || 300 | |
| 119 | + debug_output = env_to_bool("DEBUG", false) | |
| 126 | 120 | |
| 127 | - RAILS_DEFAULT_LOGGER.level = ActiveSupport::BufferedLogger::INFO unless debug_output | |
| 121 | + logger = ActiveRecord::Base.logger = Logger.new(STDOUT) | |
| 122 | + logger.level = ActiveSupport::BufferedLogger::INFO unless debug_output | |
| 128 | 123 | |
| 129 | 124 | if start_server |
| 130 | 125 | puts "Starting Solr server..." |
| ... | ... | @@ -138,37 +133,26 @@ namespace :solr do |
| 138 | 133 | alias_method :solr_optimize, :blank |
| 139 | 134 | end |
| 140 | 135 | |
| 141 | - models = includes.select { |m| m.respond_to?(:rebuild_solr_index) } | |
| 142 | - models.each do |model| | |
| 136 | + $solr_indexed_models.each do |model| | |
| 143 | 137 | |
| 144 | 138 | if clear_first |
| 145 | 139 | puts "Clearing index for #{model}..." |
| 146 | - ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "#{model.solr_configuration[:type_field]}:#{model}")) | |
| 147 | - ActsAsSolr::Post.execute(Solr::Request::Commit.new) | |
| 140 | + #ActsAsSolr::Post.execute(Solr::Request::Delete.new(:query => "#{model.solr_configuration[:type_field]}:#{model}")) | |
| 141 | + #ActsAsSolr::Post.execute(Solr::Request::Commit.new) | |
| 148 | 142 | end |
| 149 | 143 | |
| 150 | 144 | puts "Rebuilding index for #{model}..." |
| 151 | - model.rebuild_solr_index(batch_size) | |
| 145 | + model.rebuild_solr_index batch_size, :offset => offset | |
| 152 | 146 | |
| 153 | 147 | end |
| 154 | 148 | |
| 155 | - if models.empty? | |
| 149 | + if $solr_indexed_models.empty? | |
| 156 | 150 | puts "There were no models to reindex." |
| 157 | 151 | elsif optimize |
| 158 | 152 | puts "Optimizing..." |
| 159 | 153 | models.last.deferred_solr_optimize |
| 160 | 154 | end |
| 161 | 155 | |
| 162 | - if start_server | |
| 163 | - puts "Shutting down Solr server..." | |
| 164 | - Rake::Task["solr:stop"].invoke | |
| 165 | - end | |
| 166 | - | |
| 167 | - end | |
| 168 | - | |
| 169 | - def env_array_to_constants(env) | |
| 170 | - env = ENV[env] || '' | |
| 171 | - env.split(/\s*,\s*/).map { |m| m.singularize.camelize.constantize }.uniq | |
| 172 | 156 | end |
| 173 | 157 | |
| 174 | 158 | def env_to_bool(env, default) | ... | ... |