pallan-sunspot_rails 0.9.10 → 0.9.12
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +3 -2
- data/VERSION.yml +1 -1
- data/lib/sunspot/rails/configuration.rb +3 -3
- data/lib/sunspot/rails/searchable.rb +21 -21
- data/spec/configuration_spec.rb +16 -0
- data/spec/model_spec.rb +0 -22
- metadata +4 -2
data/README.rdoc
CHANGED
@@ -236,8 +236,9 @@ http://outoftime.lighthouseapp.com/projects/20339-sunspot
|
|
236
236
|
|
237
237
|
== Contributors
|
238
238
|
|
239
|
-
Mat Brown (mat@patch.com)
|
240
|
-
Peer Allan (peer.allan@gmail.com)
|
239
|
+
- Mat Brown (mat@patch.com)
|
240
|
+
- Peer Allan (peer.allan@gmail.com)
|
241
|
+
- Michael Moen (michael@underpantsgnome.com)
|
241
242
|
|
242
243
|
== License
|
243
244
|
|
data/VERSION.yml
CHANGED
@@ -54,7 +54,8 @@ module Sunspot #:nodoc:
|
|
54
54
|
end
|
55
55
|
|
56
56
|
#
|
57
|
-
# The
|
57
|
+
# The path to the Solr servlet (useful if you are running multicore).
|
58
|
+
# Default '/solr'.
|
58
59
|
#
|
59
60
|
# ==== Returns
|
60
61
|
#
|
@@ -83,8 +84,7 @@ module Sunspot #:nodoc:
|
|
83
84
|
path = File.join(::Rails.root, 'config', 'sunspot.yml')
|
84
85
|
if File.exist?(path)
|
85
86
|
File.open(path) do |file|
|
86
|
-
|
87
|
-
YAML.load(file)[RAILS_ENV]
|
87
|
+
YAML.load(file)[::Rails.env]
|
88
88
|
end
|
89
89
|
end
|
90
90
|
end
|
@@ -142,37 +142,37 @@ module Sunspot #:nodoc:
|
|
142
142
|
|
143
143
|
#
|
144
144
|
# Completely rebuild the index for this class. First removes all
|
145
|
-
# instances from the index, then loads records and save them.
|
146
|
-
# +batch_size+ argument
|
147
|
-
# database
|
145
|
+
# instances from the index, then loads records and save them. The
|
146
|
+
# +batch_size+ argument specifies how many records to load out of the
|
147
|
+
# database at a time. The default batch size is 500; if nil is passed,
|
148
|
+
# records will not be indexed in batches. By default, a commit is issued
|
149
|
+
# after each batch; passing +false+ for +batch_commit+ will disable
|
150
|
+
# this, and only issue a commit at the end of the process.
|
148
151
|
#
|
149
152
|
# ==== Parameters
|
150
153
|
#
|
151
|
-
# batch_size<Integer>:: Batch size with which to load records.
|
154
|
+
# batch_size<Integer>:: Batch size with which to load records. Passing
|
155
|
+
# 'nil' will skip batches. Default is 500.
|
156
|
+
# batch_commit<Boolean>:: Flag singaling if a commit should be done after
|
157
|
+
# after each batch is indexed, default is 'true'
|
152
158
|
#
|
153
|
-
def reindex(batch_size =
|
159
|
+
def reindex(batch_size = 500, batch_commit = true)
|
154
160
|
remove_all_from_index
|
155
161
|
unless batch_size
|
156
|
-
Sunspot.index(all)
|
162
|
+
Sunspot.index!(all)
|
157
163
|
else
|
164
|
+
record_count = count(:order => primary_key)
|
158
165
|
counter = 1
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
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
|
166
|
+
offset = 0
|
167
|
+
while(offset < record_count)
|
168
|
+
benchmark batch_size, counter do
|
169
|
+
Sunspot.index(all(:offset => offset, :limit => batch_size, :order => primary_key))
|
174
170
|
end
|
171
|
+
Sunspot.commit if batch_commit
|
172
|
+
offset += batch_size
|
173
|
+
counter += 1
|
175
174
|
end
|
175
|
+
Sunspot.commit unless batch_commit
|
176
176
|
end
|
177
177
|
end
|
178
178
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe "Configuration" do
|
4
|
+
it "should handle the 'path' property when not set" do
|
5
|
+
config = Sunspot::Rails::Configuration.new
|
6
|
+
config.path.should == '/solr'
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should handle the 'path' property when set" do
|
10
|
+
silence_stderr do
|
11
|
+
Rails.stub!(:env => 'path_test')
|
12
|
+
config = Sunspot::Rails::Configuration.new
|
13
|
+
config.path.should == '/solr/path_test'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/spec/model_spec.rb
CHANGED
@@ -173,33 +173,11 @@ describe 'ActiveRecord mixin' do
|
|
173
173
|
end
|
174
174
|
|
175
175
|
describe "using batch sizes" do
|
176
|
-
|
177
176
|
it 'should index with a batch size' do
|
178
177
|
Post.reindex(1)
|
179
178
|
Sunspot.commit
|
180
179
|
Post.search.results.to_set.should == @posts.to_set
|
181
180
|
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
181
|
end
|
204
182
|
end
|
205
183
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pallan-sunspot_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.12
|
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-06-
|
12
|
+
date: 2009-06-04 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -108,6 +108,7 @@ files:
|
|
108
108
|
- lib/sunspot/rails/searchable.rb
|
109
109
|
- lib/sunspot/rails/tasks.rb
|
110
110
|
- rails/init.rb
|
111
|
+
- spec/configuration_spec.rb
|
111
112
|
- spec/mock_app/app/controllers/application.rb
|
112
113
|
- spec/mock_app/app/controllers/application_controller.rb
|
113
114
|
- spec/mock_app/app/controllers/posts_controller.rb
|
@@ -156,6 +157,7 @@ specification_version: 3
|
|
156
157
|
summary: Rails integration for the Sunspot Solr search library
|
157
158
|
test_files:
|
158
159
|
- spec/spec_helper.rb
|
160
|
+
- spec/configuration_spec.rb
|
159
161
|
- spec/model_lifecycle_spec.rb
|
160
162
|
- spec/schema.rb
|
161
163
|
- spec/model_spec.rb
|