Commit df397df08eff0ca190a49386e05adbc2068ed51b
1 parent
e305aa61
Exists in
master
and in
29 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,14 +6,17 @@ | ||
6 | development: | 6 | development: |
7 | url: http://0.0.0.0:8982/solr | 7 | url: http://0.0.0.0:8982/solr |
8 | jvm_options: -server -Xmx128M -Xms16M | 8 | jvm_options: -server -Xmx128M -Xms16M |
9 | + timeout: 0 | ||
9 | 10 | ||
10 | production: | 11 | production: |
11 | url: http://127.0.0.1:8983/solr | 12 | url: http://127.0.0.1:8983/solr |
12 | jvm_options: -server -Xmx192M -Xms64M | 13 | jvm_options: -server -Xmx192M -Xms64M |
14 | + timeout: 0 | ||
13 | 15 | ||
14 | test: &TEST | 16 | test: &TEST |
15 | url: http://0.0.0.0:8981/solr | 17 | url: http://0.0.0.0:8981/solr |
16 | jvm_options: -server -Xmx128M -Xms16M | 18 | jvm_options: -server -Xmx128M -Xms16M |
19 | + timeout: 0 | ||
17 | 20 | ||
18 | cucumber: | 21 | cucumber: |
19 | <<: *TEST | 22 | <<: *TEST |
vendor/plugins/acts_as_solr_reloaded/lib/acts_as_solr.rb
@@ -24,19 +24,22 @@ module ActsAsSolr | @@ -24,19 +24,22 @@ module ActsAsSolr | ||
24 | class Post | 24 | class Post |
25 | class << self | 25 | class << self |
26 | def config | 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 | end | 31 | end |
29 | 32 | ||
30 | def options | 33 | def options |
31 | - @options ||= credentials.merge( :timeout => config['timeout'] ) | 34 | + @options ||= credentials.merge config |
32 | end | 35 | end |
33 | 36 | ||
34 | def credentials | 37 | def credentials |
35 | - @credentials ||= {:username => config['username'], :password => config['password']} | 38 | + @credentials ||= {:username => config[:username], :password => config[:password]} |
36 | end | 39 | end |
37 | 40 | ||
38 | def url(core) | 41 | def url(core) |
39 | - core.nil? ? config['url'] : "#{config['url']}/#{core}" | 42 | + core.nil? ? config[:url] : "#{config[:url]}/#{core}" |
40 | end | 43 | end |
41 | 44 | ||
42 | def execute(request, core = nil) | 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 | module ActsAsSolr #:nodoc: | 4 | module ActsAsSolr #:nodoc: |
2 | 5 | ||
3 | module ActsMethods | 6 | module ActsMethods |
@@ -165,6 +168,8 @@ module ActsAsSolr #:nodoc: | @@ -165,6 +168,8 @@ module ActsAsSolr #:nodoc: | ||
165 | # spatial: Default false. When true, indexes model.local.latitude and model.local.longitude as coordinates. | 168 | # spatial: Default false. When true, indexes model.local.latitude and model.local.longitude as coordinates. |
166 | def acts_as_solr(options={}, solr_options={}, &deferred_solr_configuration) | 169 | def acts_as_solr(options={}, solr_options={}, &deferred_solr_configuration) |
167 | 170 | ||
171 | + $solr_indexed_models << self | ||
172 | + | ||
168 | extend ClassMethods | 173 | extend ClassMethods |
169 | include InstanceMethods | 174 | include InstanceMethods |
170 | include CommonMethods | 175 | include CommonMethods |
@@ -370,4 +375,5 @@ module ActsAsSolr #:nodoc: | @@ -370,4 +375,5 @@ module ActsAsSolr #:nodoc: | ||
370 | end | 375 | end |
371 | end | 376 | end |
372 | end | 377 | end |
373 | -end | ||
374 | \ No newline at end of file | 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,14 +209,15 @@ module ActsAsSolr #:nodoc: | ||
209 | # If a finder block is given, it will be called to retrieve the items to index. | 209 | # If a finder block is given, it will be called to retrieve the items to index. |
210 | # This can be very useful for things such as updating based on conditions or | 210 | # This can be very useful for things such as updating based on conditions or |
211 | # using eager loading for indexed associations. | 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 | finder ||= lambda { |ar, options| ar.find(:all, options.merge({:order => self.primary_key})) } | 213 | finder ||= lambda { |ar, options| ar.find(:all, options.merge({:order => self.primary_key})) } |
214 | start_time = Time.now | 214 | start_time = Time.now |
215 | + options[:offset] ||= 0 | ||
215 | 216 | ||
216 | if batch_size > 0 | 217 | if batch_size > 0 |
217 | items_processed = 0 | 218 | items_processed = 0 |
218 | limit = batch_size | 219 | limit = batch_size |
219 | - offset = 0 | 220 | + offset = options[:offset] |
220 | begin | 221 | begin |
221 | iteration_start = Time.now | 222 | iteration_start = Time.now |
222 | items = finder.call(self, {:limit => limit, :offset => offset}) | 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,20 +111,15 @@ namespace :solr do | ||
111 | task :reindex => :environment do | 111 | task :reindex => :environment do |
112 | require File.expand_path("#{File.dirname(__FILE__)}/../../config/solr_environment") | 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 | if start_server | 124 | if start_server |
130 | puts "Starting Solr server..." | 125 | puts "Starting Solr server..." |
@@ -138,37 +133,26 @@ namespace :solr do | @@ -138,37 +133,26 @@ namespace :solr do | ||
138 | alias_method :solr_optimize, :blank | 133 | alias_method :solr_optimize, :blank |
139 | end | 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 | if clear_first | 138 | if clear_first |
145 | puts "Clearing index for #{model}..." | 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 | end | 142 | end |
149 | 143 | ||
150 | puts "Rebuilding index for #{model}..." | 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 | end | 147 | end |
154 | 148 | ||
155 | - if models.empty? | 149 | + if $solr_indexed_models.empty? |
156 | puts "There were no models to reindex." | 150 | puts "There were no models to reindex." |
157 | elsif optimize | 151 | elsif optimize |
158 | puts "Optimizing..." | 152 | puts "Optimizing..." |
159 | models.last.deferred_solr_optimize | 153 | models.last.deferred_solr_optimize |
160 | end | 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 | end | 156 | end |
173 | 157 | ||
174 | def env_to_bool(env, default) | 158 | def env_to_bool(env, default) |