outoftime-sunspot_rails 0.9.10 → 0.9.11

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/README.rdoc CHANGED
@@ -41,6 +41,8 @@ Create the file <code>config/sunspot.yml</code> and set it up for your environme
41
41
 
42
42
  production:
43
43
  <<: *common
44
+ solr:
45
+ path: /solr/myindex
44
46
 
45
47
  development:
46
48
  <<: *common
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 10
2
+ :patch: 11
3
3
  :major: 0
4
4
  :minor: 9
@@ -1,10 +1,10 @@
1
1
  module Sunspot #:nodoc:
2
2
  module Rails #:nodoc:
3
- #
3
+ #
4
4
  # Sunspot::Rails is configured via the config/sunspot.yml file, which
5
5
  # contains properties keyed by environment name. A sample sunspot.yml file
6
6
  # would look like:
7
- #
7
+ #
8
8
  # development:
9
9
  # solr:
10
10
  # hostname: localhost
@@ -14,12 +14,18 @@ module Sunspot #:nodoc:
14
14
  # hostname: localhost
15
15
  # port: 8983
16
16
  #
17
+ # production:
18
+ # solr:
19
+ # hostname: localhost
20
+ # port: 8983
21
+ # path: /solr/myindex
22
+ #
17
23
  # Sunspot::Rails uses the configuration to set up the Solr connection, as
18
24
  # well as for starting Solr with the appropriate port using the
19
25
  # <code>rake sunspot:solr:start</code> task.
20
26
  #
21
27
  class Configuration
22
- #
28
+ #
23
29
  # The host name at which to connect to Solr. Default 'localhost'.
24
30
  #
25
31
  # ==== Returns
@@ -27,13 +33,13 @@ module Sunspot #:nodoc:
27
33
  # String:: host name
28
34
  #
29
35
  def hostname
30
- @hostname ||=
36
+ @hostname ||=
31
37
  if user_configuration.has_key?('solr')
32
38
  user_configuration['solr']['hostname']
33
39
  end || 'localhost'
34
40
  end
35
41
 
36
- #
42
+ #
37
43
  # The port at which to connect to Solr. Default 8983.
38
44
  #
39
45
  # ==== Returns
@@ -47,9 +53,23 @@ module Sunspot #:nodoc:
47
53
  end || 8983
48
54
  end
49
55
 
56
+ #
57
+ # The URL to call if you are running Solr with multicore. Default '/solr'.
58
+ #
59
+ # ==== Returns
60
+ #
61
+ # String:: path
62
+ #
63
+ def path
64
+ @path ||=
65
+ if user_configuration.has_key?('solr')
66
+ "#{user_configuration['solr']['path'] || '/solr'}"
67
+ end
68
+ end
69
+
50
70
  private
51
71
 
52
- #
72
+ #
53
73
  # Memoized hash of configuration options for the current Rails environment
54
74
  # as specified in config/sunspot.yml
55
75
  #
@@ -63,7 +83,8 @@ module Sunspot #:nodoc:
63
83
  path = File.join(::Rails.root, 'config', 'sunspot.yml')
64
84
  if File.exist?(path)
65
85
  File.open(path) do |file|
66
- YAML.load(file)[::Rails.env]
86
+ # only changed this to allow me to test the path attribute
87
+ YAML.load(file)[RAILS_ENV]
67
88
  end
68
89
  end
69
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. If the
146
- # +batch_size+ argument is passed, records will be retrieved from the
147
- # database in batches of that size (recommended for larger data sets).
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. Default is none.
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 = nil)
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
- 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
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
 
data/rails/init.rb CHANGED
@@ -2,7 +2,7 @@ require 'sunspot'
2
2
 
3
3
  Sunspot.config.solr.url = URI::HTTP.build(:host => Sunspot::Rails.configuration.hostname,
4
4
  :port => Sunspot::Rails.configuration.port,
5
- :path => '/solr').to_s
5
+ :path => Sunspot::Rails.configuration.path).to_s
6
6
 
7
7
  Sunspot::Adapters::InstanceAdapter.register(Sunspot::Rails::Adapters::ActiveRecordInstanceAdapter, ActiveRecord::Base)
8
8
  Sunspot::Adapters::DataAccessor.register(Sunspot::Rails::Adapters::ActiveRecordDataAccessor, ActiveRecord::Base)
@@ -0,0 +1,17 @@
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_ENV = 'path_test'
12
+ config ||= Sunspot::Rails::Configuration.new
13
+ config.path.should == '/solr/path_test'
14
+ RAILS_ENV = 'test'
15
+ end
16
+ end
17
+ end
@@ -6,3 +6,8 @@ development:
6
6
  solr:
7
7
  hostname: localhost
8
8
  port: 8981
9
+ path_test:
10
+ solr:
11
+ hostname: localhost
12
+ port: 8981
13
+ path: /solr/path_test
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
data/spec/spec_helper.rb CHANGED
@@ -14,6 +14,13 @@ def load_schema
14
14
  $stdout = stdout
15
15
  end
16
16
 
17
+ def silence_stderr(&block)
18
+ stderr = $stderr
19
+ $stderr = StringIO.new
20
+ yield
21
+ $stderr = stderr
22
+ end
23
+
17
24
  Spec::Runner.configure do |config|
18
25
  config.before(:each) do
19
26
  Sunspot.remove_all
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.10
4
+ version: 0.9.11
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-03 00:00:00 -07:00
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