outoftime-sunspot_rails 0.9.9 → 0.9.10

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/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Permission is hereby granted, free of charge, to any person obtaining
2
+ a copy of this software and associated documentation files (the
3
+ 'Software'), to deal in the Software without restriction, including
4
+ without limitation the rights to use, copy, modify, merge, publish,
5
+ distribute, sublicense, and/or sell copies of the Software, and to
6
+ permit persons to whom the Software is furnished to do so, subject to
7
+ the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be
10
+ included in all copies or substantial portions of the Software.
11
+
12
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
13
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
15
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
16
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
17
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
18
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc CHANGED
@@ -234,27 +234,9 @@ http://outoftime.lighthouseapp.com/projects/20339-sunspot
234
234
 
235
235
  == Contributors
236
236
 
237
- Mat Brown <mat@patch.com>
238
-
239
- == MIT License
240
-
241
- Copyright (c) 2009 Mat Brown
242
-
243
- Permission is hereby granted, free of charge, to any person obtaining
244
- a copy of this software and associated documentation files (the
245
- "Software"), to deal in the Software without restriction, including
246
- without limitation the rights to use, copy, modify, merge, publish,
247
- distribute, sublicense, and/or sell copies of the Software, and to
248
- permit persons to whom the Software is furnished to do so, subject to
249
- the following conditions:
250
-
251
- The above copyright notice and this permission notice shall be
252
- included in all copies or substantial portions of the Software.
253
-
254
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
255
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
256
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
257
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
258
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
259
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
260
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
237
+ Mat Brown (mat@patch.com)
238
+ Peer Allan (peer.allan@gmail.com)
239
+
240
+ == License
241
+
242
+ Sunspot::Rails is distributed under the MIT License, copyright (c) 2009 Mat Brown
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 9
2
+ :patch: 10
3
3
  :major: 0
4
4
  :minor: 9
@@ -143,22 +143,35 @@ module Sunspot #:nodoc:
143
143
  #
144
144
  # Completely rebuild the index for this class. First removes all
145
145
  # instances from the index, then loads records and save them. If the
146
- # +batch+ argument is passed, records will be retrieved from the
146
+ # +batch_size+ argument is passed, records will be retrieved from the
147
147
  # database in batches of that size (recommended for larger data sets).
148
148
  #
149
149
  # ==== Parameters
150
150
  #
151
- # batch<Integer>:: Batch size with which to load records. Default is none.
151
+ # batch_size<Integer>:: Batch size with which to load records. Default is none.
152
152
  #
153
- def reindex(batch = nil)
153
+ def reindex(batch_size = nil)
154
154
  remove_all_from_index
155
- unless batch
155
+ unless batch_size
156
156
  Sunspot.index(all)
157
157
  else
158
- offset = 0
159
- while(offset < count)
160
- Sunspot.index(all(:offset => offset, :limit => batch))
161
- offset += batch
158
+ counter = 1
159
+ if self.respond_to?(:find_in_batches)
160
+ self.find_in_batches(:batch_size => batch_size) do |batch|
161
+ benchmark batch_size, counter do
162
+ Sunspot.index(batch)
163
+ end
164
+ counter += 1
165
+ end
166
+ else
167
+ offset = 0
168
+ while(offset < count)
169
+ benchmark batch_size, counter do
170
+ Sunspot.index(all(:offset => offset, :limit => batch_size))
171
+ end
172
+ offset += batch_size
173
+ counter += 1
174
+ end
162
175
  end
163
176
  end
164
177
  end
@@ -206,6 +219,20 @@ module Sunspot #:nodoc:
206
219
  def searchable?
207
220
  true
208
221
  end
222
+
223
+ protected
224
+
225
+ #
226
+ # Does some logging for benchmarking indexing performance
227
+ #
228
+ def benchmark(batch_size, counter, &block)
229
+ start = Time.now
230
+ logger.info("[#{Time.now}] Start Indexing")
231
+ yield
232
+ elapsed = Time.now-start
233
+ logger.info("[#{Time.now}] Completed Indexing. Rows indexed #{counter * batch_size}. Rows/sec: #{batch_size/elapsed.to_f} (Elapsed: #{elapsed} sec.)")
234
+ end
235
+
209
236
  end
210
237
 
211
238
  module InstanceMethods
data/spec/model_spec.rb CHANGED
@@ -163,12 +163,6 @@ describe 'ActiveRecord mixin' do
163
163
  Post.search.results.to_set.should == @posts.to_set
164
164
  end
165
165
 
166
- it 'should index with a batch size' do
167
- Post.reindex(1)
168
- Sunspot.commit
169
- Post.search.results.to_set.should == @posts.to_set
170
- end
171
-
172
166
  it 'should remove all currently indexed instances' do
173
167
  old_post = Post.create!
174
168
  old_post.index!
@@ -177,5 +171,35 @@ describe 'ActiveRecord mixin' do
177
171
  Sunspot.commit
178
172
  Post.search.results.to_set.should == @posts.to_set
179
173
  end
174
+
175
+ describe "using batch sizes" do
176
+
177
+ it 'should index with a batch size' do
178
+ Post.reindex(1)
179
+ Sunspot.commit
180
+ Post.search.results.to_set.should == @posts.to_set
181
+ end
182
+
183
+ it "should look for find_in_batches" do
184
+ pending "Have to figure out how to remove stubs for Class Methods so this will work"
185
+ Post.stub!(:respond_to?).with(:to_ary).and_return(false)
186
+ Post.should_receive(:respond_to?).with(:find_in_batches).and_return(true)
187
+ Post.reindex(100)
188
+ end
189
+
190
+ it "should use find_in_batches" do
191
+ pending "Have to figure out how to remove stubs for Class Methods so this will work"
192
+ Post.should_receive(:find_in_batches).with(:batch_size => 100).and_return([])
193
+ Post.reindex(100)
194
+ end
195
+
196
+ it "should find all with the batch size and offset if it can't use find_by_batches" do
197
+ pending "Have to figure out how to remove stubs for Class Methods so this will work"
198
+ Post.stub!(:respond_to?).with(:to_ary).and_return(false)
199
+ Post.stub!(:respond_to?).with(:find_in_batches).and_return(false)
200
+ Post.should_receive(:all).with(:offset => 0, :limit => 100).and_return([])
201
+ Post.reindex(100)
202
+ end
203
+ end
180
204
  end
181
205
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: outoftime-sunspot_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.9
4
+ version: 0.9.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mat Brown
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-27 00:00:00 -07:00
12
+ date: 2009-06-03 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -89,8 +89,10 @@ executables: []
89
89
  extensions: []
90
90
 
91
91
  extra_rdoc_files:
92
+ - LICENSE
92
93
  - README.rdoc
93
94
  files:
95
+ - LICENSE
94
96
  - MIT-LICENSE
95
97
  - README.rdoc
96
98
  - Rakefile