sunspot_rails 1.3.3 → 2.0.0.pre.111215

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,4 +1,10 @@
1
- == 1.3.0
1
+ == 2.0.0
2
+ * Finds orphaned objects in batches to avoid excessive memory use (Peer Allan)
3
+ * Default batch size can be specified by setting `Sunspot.config.indexing.default_batch_size`
4
+ (Peer Allan)
5
+ * Explanation of `progress_bar` is written to stdout instead of stderr (Matt Gornick)
6
+
7
+ == 1.3.0 2011-11-26
2
8
  * `Model.index` correctly uses `:first_id` option (Hamza Khan-Cheema)
3
9
  * Solr request performance is instrumented in Rails (Paco Guzmán)
4
10
  * Reindexing tasks display a progress bar if `progress_bar` gem is available (Paul Carey)
@@ -1,6 +1,6 @@
1
1
  source :rubygems
2
2
 
3
- gem 'rails', '3.0.12'
3
+ gem 'rails', '3.0.11'
4
4
  gem 'sqlite3-ruby', '~> 1.3.1'
5
5
 
6
6
  gem 'sunspot', :path => File.expand_path('../../../sunspot', __FILE__)
@@ -1,6 +1,6 @@
1
1
  source :rubygems
2
2
 
3
- gem 'rails', '3.1.4'
3
+ gem 'rails', '3.1.3'
4
4
  gem 'sqlite3-ruby', '~> 1.3.1'
5
5
 
6
6
  gem 'sunspot', :path => File.expand_path('../../../sunspot', __FILE__)
@@ -1,7 +1,7 @@
1
1
  module Sunspot
2
2
  module Rails
3
3
  class Railtie < ::Rails::Railtie
4
- initializer 'sunspot_rails.init', :before=> :load_config_initializers do
4
+ initializer 'sunspot_rails.init' do
5
5
  Sunspot.session = Sunspot::Rails.build_session
6
6
  ActiveSupport.on_load(:active_record) do
7
7
  Sunspot::Adapters::InstanceAdapter.register(Sunspot::Rails::Adapters::ActiveRecordInstanceAdapter, ActiveRecord::Base)
@@ -238,7 +238,7 @@ module Sunspot #:nodoc:
238
238
  #
239
239
  def solr_index(opts={})
240
240
  options = {
241
- :batch_size => 50,
241
+ :batch_size => Sunspot.config.indexing.default_batch_size,
242
242
  :batch_commit => true,
243
243
  :include => self.sunspot_options[:include],
244
244
  :start => opts.delete(:first_id) || 0
@@ -275,13 +275,19 @@ module Sunspot #:nodoc:
275
275
  # wrong. Usually you will want to rectify the situation by calling
276
276
  # #clean_index_orphans or #reindex
277
277
  #
278
+ # ==== Options (passed as a hash)
279
+ #
280
+ # batch_size<Integer>:: Batch size with which to load records. Passing
281
+ # Default is 1000 (from ActiveRecord).
282
+ #
278
283
  # ==== Returns
279
284
  #
280
285
  # Array:: Collection of IDs that exist in Solr but not in the database
281
- def solr_index_orphans
286
+ def solr_index_orphans(opts={})
287
+ batch_size = opts[:batch_size] || Sunspot.config.indexing.default_batch_size
282
288
  count = self.count
283
289
  indexed_ids = solr_search_ids { paginate(:page => 1, :per_page => count) }.to_set
284
- all(:select => 'id').each do |object|
290
+ find_each(:select => 'id', :batch_size => batch_size) do |object|
285
291
  indexed_ids.delete(object.id)
286
292
  end
287
293
  indexed_ids.to_a
@@ -293,8 +299,13 @@ module Sunspot #:nodoc:
293
299
  # circumstances, this should not be necessary; this method is provided
294
300
  # in case something goes wrong.
295
301
  #
296
- def solr_clean_index_orphans
297
- solr_index_orphans.each do |id|
302
+ # ==== Options (passed as a hash)
303
+ #
304
+ # batch_size<Integer>:: Batch size with which to load records
305
+ # Default is 50
306
+ #
307
+ def solr_clean_index_orphans(opts={})
308
+ solr_index_orphans(opts).each do |id|
298
309
  new do |fake_instance|
299
310
  fake_instance.id = id
300
311
  end.solr_remove_from_index
@@ -7,11 +7,12 @@ module Sunspot
7
7
  alias_method_chain :execute, :as_instrumentation
8
8
  end
9
9
 
10
-
11
- def execute_with_as_instrumentation(path, params={}, *extra)
12
- ActiveSupport::Notifications.instrument("request.rsolr",
13
- {:path => path, :parameters => params}) do
14
- execute_without_as_instrumentation(path, params, *extra)
10
+ module InstanceMethods
11
+ def execute_with_as_instrumentation(path, params={}, *extra)
12
+ ActiveSupport::Notifications.instrument("request.rsolr",
13
+ {:path => path, :parameters => params}) do
14
+ execute_without_as_instrumentation(path, params, *extra)
15
+ end
15
16
  end
16
17
  end
17
18
  end
@@ -55,11 +55,7 @@ module Sunspot
55
55
  def new_search(*types)
56
56
  Search.new
57
57
  end
58
-
59
- def more_like_this(*args)
60
- Search.new
61
- end
62
-
58
+
63
59
  def new_more_like_this(*args)
64
60
  Search.new
65
61
  end
@@ -15,10 +15,6 @@ namespace :sunspot do
15
15
  # # batchs of 1000
16
16
  # $ rake sunspot:reindex[,Post+Author] # reindex Post and Author model
17
17
  task :reindex, [:batch_size, :models] => [:environment] do |t, args|
18
-
19
- # Retry once or gracefully fail for a 5xx error so we don't break reindexing
20
- Sunspot.session = Sunspot::SessionProxy::Retry5xxSessionProxy.new(Sunspot.session)
21
-
22
18
  # Set up general options for reindexing
23
19
  reindex_options = { :batch_commit => false }
24
20
 
@@ -48,26 +44,22 @@ namespace :sunspot do
48
44
  total_documents = sunspot_models.map { | m | m.count }.sum
49
45
  reindex_options[:progress_bar] = ProgressBar.new(total_documents)
50
46
  rescue LoadError => e
51
- $stderr.puts "Skipping progress bar: for progress reporting, add gem 'progress_bar' to your Gemfile"
47
+ $stdout.puts "Skipping progress bar: for progress reporting, add gem 'progress_bar' to your Gemfile"
52
48
  rescue Exception => e
53
49
  $stderr.puts "Error using progress bar: #{e.message}"
54
50
  end
55
-
51
+
56
52
  # Finally, invoke the class-level solr_reindex on each model
57
53
  sunspot_models.each do |model|
58
54
  model.solr_reindex(reindex_options)
59
55
  end
60
56
  end
61
57
 
62
- def sunspot_solr_in_load_path?
63
- # http://www.rubular.com/r/rJGDh7eOSc
64
- $:.any? { |path| path =~ %r{sunspot_solr(-[^/]+)?/lib$} }
65
- end
66
58
 
67
- unless sunspot_solr_in_load_path?
59
+ unless defined?(Sunspot::Solr)
68
60
  namespace :solr do
69
- task :moved_to_sunspot_solr do
70
- abort %(
61
+ task :moved_to_sunspot_solr do
62
+ abort %(
71
63
  Note: This task has been moved to the sunspot_solr gem. To install, start and
72
64
  stop a local Solr instance, please add sunspot_solr to your Gemfile:
73
65
 
@@ -76,19 +68,17 @@ namespace :sunspot do
76
68
  end
77
69
 
78
70
  )
79
- end
80
-
71
+ end
72
+
81
73
  desc 'Start the Solr instance'
82
74
  task :start => :moved_to_sunspot_solr
83
-
84
75
  desc 'Run the Solr instance in the foreground'
85
76
  task :run => :moved_to_sunspot_solr
86
-
87
77
  desc 'Stop the Solr instance'
88
78
  task :stop => :moved_to_sunspot_solr
89
-
90
- # for backwards compatibility
79
+ # for backwards compatibility
91
80
  task :reindex => :"sunspot:reindex"
92
81
  end
93
82
  end
83
+
94
84
  end
data/spec/model_spec.rb CHANGED
@@ -211,6 +211,12 @@ describe 'ActiveRecord mixin' do
211
211
  it 'should return IDs of objects that are in the index but not the database' do
212
212
  Post.index_orphans.should == [@posts.first.id]
213
213
  end
214
+
215
+ it 'should find the orphans in batches to improve performance' do
216
+ Post.should_receive(:find_each).with(hash_including(:batch_size => 10)).and_return([])
217
+ Post.index_orphans(:batch_size => 10)
218
+ end
219
+
214
220
  end
215
221
 
216
222
  describe 'clean_index_orphans()' do
@@ -79,6 +79,11 @@ describe 'specs with Sunspot stubbed' do
79
79
  Post.search
80
80
  end
81
81
 
82
+ it 'should not execute a search when #search called' do
83
+ @session.should_not_receive(:search)
84
+ Post.search
85
+ end
86
+
82
87
  it 'should not execute a search when #search called with parameters' do
83
88
  @session.should_not_receive(:search)
84
89
  Post.search(:include => :blog, :select => 'id, title')
@@ -89,11 +94,6 @@ describe 'specs with Sunspot stubbed' do
89
94
  Sunspot.new_search(Post).should respond_to(:execute)
90
95
  end
91
96
 
92
- it 'should not send more_like_this to session' do
93
- @session.should_not_receive(:more_like_this)
94
- Sunspot.more_like_this(@post)
95
- end
96
-
97
97
  describe 'stub search' do
98
98
  before :each do
99
99
  @search = Post.search
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sunspot_rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
5
- prerelease:
4
+ prerelease: true
6
5
  segments:
7
- - 1
8
- - 3
9
- - 3
10
- version: 1.3.3
6
+ - 2
7
+ - 0
8
+ - 0
9
+ - pre
10
+ - 111215
11
+ version: 2.0.0.pre.111215
11
12
  platform: ruby
12
13
  authors:
13
14
  - Mat Brown
@@ -33,33 +34,32 @@ autorequire:
33
34
  bindir: bin
34
35
  cert_chain: []
35
36
 
36
- date: 2012-06-11 00:00:00 Z
37
+ date: 2011-12-15 00:00:00 -07:00
38
+ default_executable:
37
39
  dependencies:
38
40
  - !ruby/object:Gem::Dependency
39
41
  name: sunspot
40
42
  prerelease: false
41
43
  requirement: &id001 !ruby/object:Gem::Requirement
42
- none: false
43
44
  requirements:
44
45
  - - "="
45
46
  - !ruby/object:Gem::Version
46
- hash: 29
47
47
  segments:
48
- - 1
49
- - 3
50
- - 3
51
- version: 1.3.3
48
+ - 2
49
+ - 0
50
+ - 0
51
+ - pre
52
+ - 111215
53
+ version: 2.0.0.pre.111215
52
54
  type: :runtime
53
55
  version_requirements: *id001
54
56
  - !ruby/object:Gem::Dependency
55
57
  name: nokogiri
56
58
  prerelease: false
57
59
  requirement: &id002 !ruby/object:Gem::Requirement
58
- none: false
59
60
  requirements:
60
61
  - - ">="
61
62
  - !ruby/object:Gem::Version
62
- hash: 3
63
63
  segments:
64
64
  - 0
65
65
  version: "0"
@@ -69,11 +69,9 @@ dependencies:
69
69
  name: rspec
70
70
  prerelease: false
71
71
  requirement: &id003 !ruby/object:Gem::Requirement
72
- none: false
73
72
  requirements:
74
73
  - - ~>
75
74
  - !ruby/object:Gem::Version
76
- hash: 11
77
75
  segments:
78
76
  - 1
79
77
  - 2
@@ -84,11 +82,9 @@ dependencies:
84
82
  name: rspec-rails
85
83
  prerelease: false
86
84
  requirement: &id004 !ruby/object:Gem::Requirement
87
- none: false
88
85
  requirements:
89
86
  - - ~>
90
87
  - !ruby/object:Gem::Version
91
- hash: 11
92
88
  segments:
93
89
  - 1
94
90
  - 2
@@ -118,9 +114,8 @@ files:
118
114
  - dev_tasks/spec.rake
119
115
  - dev_tasks/todo.rake
120
116
  - gemfiles/rails-2.3.14
121
- - gemfiles/rails-3.0.12
122
- - gemfiles/rails-3.1.4
123
- - gemfiles/rails-3.2.3
117
+ - gemfiles/rails-3.0.11
118
+ - gemfiles/rails-3.1.3
124
119
  - generators/sunspot/sunspot_generator.rb
125
120
  - generators/sunspot/templates/sunspot.yml
126
121
  - install.rb
@@ -171,6 +166,7 @@ files:
171
166
  - spec/stub_session_proxy_spec.rb
172
167
  - sunspot_rails.gemspec
173
168
  - tmp/.gitkeep
169
+ has_rdoc: true
174
170
  homepage: http://github.com/outoftime/sunspot/tree/master/sunspot_rails
175
171
  licenses: []
176
172
 
@@ -184,27 +180,25 @@ rdoc_options:
184
180
  require_paths:
185
181
  - lib
186
182
  required_ruby_version: !ruby/object:Gem::Requirement
187
- none: false
188
183
  requirements:
189
184
  - - ">="
190
185
  - !ruby/object:Gem::Version
191
- hash: 3
192
186
  segments:
193
187
  - 0
194
188
  version: "0"
195
189
  required_rubygems_version: !ruby/object:Gem::Requirement
196
- none: false
197
190
  requirements:
198
- - - ">="
191
+ - - ">"
199
192
  - !ruby/object:Gem::Version
200
- hash: 3
201
193
  segments:
202
- - 0
203
- version: "0"
194
+ - 1
195
+ - 3
196
+ - 1
197
+ version: 1.3.1
204
198
  requirements: []
205
199
 
206
200
  rubyforge_project: sunspot
207
- rubygems_version: 1.8.15
201
+ rubygems_version: 1.3.6
208
202
  signing_key:
209
203
  specification_version: 3
210
204
  summary: Rails integration for the Sunspot Solr search library
data/gemfiles/rails-3.2.3 DELETED
@@ -1,12 +0,0 @@
1
- source :rubygems
2
-
3
- gem 'rails', '3.2.3'
4
- gem 'sqlite3-ruby', '~> 1.3.1'
5
-
6
- gem 'sunspot', :path => File.expand_path('../../../sunspot', __FILE__)
7
- gem 'sunspot_solr', :path => File.expand_path('../../../sunspot_solr', __FILE__)
8
- gem 'sunspot_rails', :path => File.expand_path('../..', __FILE__)
9
-
10
- group :test do
11
- gem 'rspec-rails', '~> 2.8.1'
12
- end