sunspot_rails 0.10.7 → 0.10.8
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/VERSION.yml +1 -1
- data/dev_tasks/gemspec.rake +1 -2
- data/lib/sunspot/rails/request_lifecycle.rb +1 -1
- data/lib/sunspot/rails/searchable.rb +16 -12
- data/lib/sunspot/rails.rb +0 -13
- data/rails/init.rb +4 -0
- data/spec/model_lifecycle_spec.rb +3 -3
- data/spec/model_spec.rb +18 -18
- data/spec/spec_helper.rb +2 -2
- metadata +13 -16
- data/spec/mock_app/db/test.db +0 -1
- data/spec/session_spec.rb +0 -11
data/VERSION.yml
CHANGED
data/dev_tasks/gemspec.rake
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
begin
|
2
|
-
gem 'technicalpickles-jeweler', '~> 1.0'
|
3
2
|
require 'jeweler'
|
4
3
|
Jeweler::Tasks.new do |s|
|
5
4
|
s.name = 'sunspot_rails'
|
@@ -38,5 +37,5 @@ end
|
|
38
37
|
|
39
38
|
namespace :release do
|
40
39
|
desc "Release gem to RubyForge and GitHub"
|
41
|
-
task :all => [:"rubyforge:release:gem", :"gemcutter:release"]
|
40
|
+
task :all => [:release, :"rubyforge:release:gem", :"gemcutter:release"]
|
42
41
|
end
|
@@ -9,7 +9,7 @@ module Sunspot #:nodoc:
|
|
9
9
|
class <<self
|
10
10
|
def included(base) #:nodoc:
|
11
11
|
base.after_filter do
|
12
|
-
Sunspot
|
12
|
+
Sunspot.commit_if_dirty if Sunspot::Rails.configuration.auto_commit_after_request?
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -104,7 +104,7 @@ module Sunspot #:nodoc:
|
|
104
104
|
# Sunspot::Search:: Object containing results, totals, facets, etc.
|
105
105
|
#
|
106
106
|
def search(&block)
|
107
|
-
Sunspot
|
107
|
+
Sunspot.search(self, &block)
|
108
108
|
end
|
109
109
|
|
110
110
|
#
|
@@ -125,7 +125,7 @@ module Sunspot #:nodoc:
|
|
125
125
|
# Remove instances of this class from the Solr index.
|
126
126
|
#
|
127
127
|
def remove_all_from_index
|
128
|
-
Sunspot
|
128
|
+
Sunspot.remove_all(self)
|
129
129
|
end
|
130
130
|
|
131
131
|
#
|
@@ -136,8 +136,8 @@ module Sunspot #:nodoc:
|
|
136
136
|
# XXX Sunspot should implement remove_all!()
|
137
137
|
#
|
138
138
|
def remove_all_from_index!
|
139
|
-
|
140
|
-
Sunspot
|
139
|
+
Sunspot.remove_all(self)
|
140
|
+
Sunspot.commit
|
141
141
|
end
|
142
142
|
|
143
143
|
#
|
@@ -180,20 +180,20 @@ module Sunspot #:nodoc:
|
|
180
180
|
options = { :batch_size => 500, :batch_commit => true, :include => []}.merge(opts)
|
181
181
|
remove_all_from_index
|
182
182
|
unless options[:batch_size]
|
183
|
-
Sunspot
|
183
|
+
Sunspot.index!(all(:include => options[:include]))
|
184
184
|
else
|
185
185
|
record_count = count
|
186
186
|
counter = 1
|
187
187
|
offset = 0
|
188
188
|
while(offset < record_count)
|
189
189
|
benchmark options[:batch_size], counter do
|
190
|
-
Sunspot
|
190
|
+
Sunspot.index(all(:include => options[:include], :offset => offset, :limit => options[:batch_size], :order => primary_key))
|
191
191
|
end
|
192
|
-
Sunspot
|
192
|
+
Sunspot.commit if options[:batch_commit]
|
193
193
|
offset += options[:batch_size]
|
194
194
|
counter += 1
|
195
195
|
end
|
196
|
-
Sunspot
|
196
|
+
Sunspot.commit unless options[:batch_commit]
|
197
197
|
end
|
198
198
|
end
|
199
199
|
|
@@ -267,14 +267,14 @@ module Sunspot #:nodoc:
|
|
267
267
|
# manually.
|
268
268
|
#
|
269
269
|
def index
|
270
|
-
Sunspot
|
270
|
+
Sunspot.index(self)
|
271
271
|
end
|
272
272
|
|
273
273
|
#
|
274
274
|
# Index the model in Solr and immediately commit. See #index
|
275
275
|
#
|
276
276
|
def index!
|
277
|
-
Sunspot
|
277
|
+
Sunspot.index!(self)
|
278
278
|
end
|
279
279
|
|
280
280
|
#
|
@@ -285,15 +285,19 @@ module Sunspot #:nodoc:
|
|
285
285
|
# manually.
|
286
286
|
#
|
287
287
|
def remove_from_index
|
288
|
-
Sunspot
|
288
|
+
Sunspot.remove(self)
|
289
289
|
end
|
290
290
|
|
291
291
|
#
|
292
292
|
# Remove the model from the Solr index and commit immediately. See
|
293
293
|
# #remove_from_index
|
294
294
|
#
|
295
|
+
#---
|
296
|
+
#FIXME Sunspot should implement remove!()
|
297
|
+
#
|
295
298
|
def remove_from_index!
|
296
|
-
Sunspot
|
299
|
+
Sunspot.remove(self)
|
300
|
+
Sunspot.commit
|
297
301
|
end
|
298
302
|
end
|
299
303
|
end
|
data/lib/sunspot/rails.rb
CHANGED
@@ -8,19 +8,6 @@ module Sunspot #:nodoc:
|
|
8
8
|
def configuration
|
9
9
|
@configuration ||= Sunspot::Rails::Configuration.new
|
10
10
|
end
|
11
|
-
|
12
|
-
def session
|
13
|
-
Thread.current[:sunspot_rails_session] ||=
|
14
|
-
begin
|
15
|
-
session = Sunspot::Session.new
|
16
|
-
session.config.solr.url = URI::HTTP.build(
|
17
|
-
:host => configuration.hostname,
|
18
|
-
:port => configuration.port,
|
19
|
-
:path => configuration.path
|
20
|
-
).to_s
|
21
|
-
session
|
22
|
-
end
|
23
|
-
end
|
24
11
|
end
|
25
12
|
end
|
26
13
|
end
|
data/rails/init.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
require 'sunspot'
|
2
2
|
|
3
|
+
Sunspot.config.solr.url = URI::HTTP.build(:host => Sunspot::Rails.configuration.hostname,
|
4
|
+
:port => Sunspot::Rails.configuration.port,
|
5
|
+
:path => Sunspot::Rails.configuration.path).to_s
|
6
|
+
|
3
7
|
Sunspot::Adapters::InstanceAdapter.register(Sunspot::Rails::Adapters::ActiveRecordInstanceAdapter, ActiveRecord::Base)
|
4
8
|
Sunspot::Adapters::DataAccessor.register(Sunspot::Rails::Adapters::ActiveRecordDataAccessor, ActiveRecord::Base)
|
5
9
|
ActiveRecord::Base.module_eval { include(Sunspot::Rails::Searchable) }
|
@@ -4,7 +4,7 @@ describe 'searchable with lifecycle' do
|
|
4
4
|
describe 'on create' do
|
5
5
|
before :each do
|
6
6
|
@post = PostWithAuto.create
|
7
|
-
Sunspot
|
7
|
+
Sunspot.commit
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'should automatically index' do
|
@@ -16,7 +16,7 @@ describe 'searchable with lifecycle' do
|
|
16
16
|
before :each do
|
17
17
|
@post = PostWithAuto.create
|
18
18
|
@post.update_attributes(:title => 'Test 1')
|
19
|
-
Sunspot
|
19
|
+
Sunspot.commit
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'should automatically update index' do
|
@@ -28,7 +28,7 @@ describe 'searchable with lifecycle' do
|
|
28
28
|
before :each do
|
29
29
|
@post = PostWithAuto.create
|
30
30
|
@post.destroy
|
31
|
-
Sunspot
|
31
|
+
Sunspot.commit
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'should automatically remove it from the index' do
|
data/spec/model_spec.rb
CHANGED
@@ -12,7 +12,7 @@ describe 'ActiveRecord mixin' do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'should index the model' do
|
15
|
-
Sunspot
|
15
|
+
Sunspot.commit
|
16
16
|
Post.search.results.should == [@post]
|
17
17
|
end
|
18
18
|
end
|
@@ -40,7 +40,7 @@ describe 'ActiveRecord mixin' do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'should remove the model from the index' do
|
43
|
-
Sunspot
|
43
|
+
Sunspot.commit
|
44
44
|
Post.search.results.should be_empty
|
45
45
|
end
|
46
46
|
end
|
@@ -59,8 +59,8 @@ describe 'ActiveRecord mixin' do
|
|
59
59
|
|
60
60
|
describe 'remove_all_from_index' do
|
61
61
|
before :each do
|
62
|
-
@posts = Array.new(10) { Post.create! }.each { |post| Sunspot
|
63
|
-
Sunspot
|
62
|
+
@posts = Array.new(10) { Post.create! }.each { |post| Sunspot.index(post) }
|
63
|
+
Sunspot.commit
|
64
64
|
Post.remove_all_from_index
|
65
65
|
end
|
66
66
|
|
@@ -69,15 +69,15 @@ describe 'ActiveRecord mixin' do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
it 'should remove all instances from the index' do
|
72
|
-
Sunspot
|
72
|
+
Sunspot.commit
|
73
73
|
Post.search.results.should be_empty
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
77
|
describe 'remove_all_from_index!' do
|
78
78
|
before :each do
|
79
|
-
Array.new(10) { Post.create! }.each { |post| Sunspot
|
80
|
-
Sunspot
|
79
|
+
Array.new(10) { Post.create! }.each { |post| Sunspot.index(post) }
|
80
|
+
Sunspot.commit
|
81
81
|
Post.remove_all_from_index!
|
82
82
|
end
|
83
83
|
|
@@ -115,7 +115,7 @@ describe 'ActiveRecord mixin' do
|
|
115
115
|
describe 'search_ids()' do
|
116
116
|
before :each do
|
117
117
|
@posts = Array.new(2) { Post.create! }.each { |post| post.index }
|
118
|
-
Sunspot
|
118
|
+
Sunspot.commit
|
119
119
|
end
|
120
120
|
|
121
121
|
it 'should return IDs' do
|
@@ -136,7 +136,7 @@ describe 'ActiveRecord mixin' do
|
|
136
136
|
describe 'index_orphans()' do
|
137
137
|
before :each do
|
138
138
|
@posts = Array.new(2) { Post.create }.each { |post| post.index }
|
139
|
-
Sunspot
|
139
|
+
Sunspot.commit
|
140
140
|
@posts.first.destroy
|
141
141
|
end
|
142
142
|
|
@@ -148,13 +148,13 @@ describe 'ActiveRecord mixin' do
|
|
148
148
|
describe 'clean_index_orphans()' do
|
149
149
|
before :each do
|
150
150
|
@posts = Array.new(2) { Post.create }.each { |post| post.index }
|
151
|
-
Sunspot
|
151
|
+
Sunspot.commit
|
152
152
|
@posts.first.destroy
|
153
153
|
end
|
154
154
|
|
155
155
|
it 'should remove orphans from the index' do
|
156
156
|
Post.clean_index_orphans
|
157
|
-
Sunspot
|
157
|
+
Sunspot.commit
|
158
158
|
Post.search.results.should == [@posts.last]
|
159
159
|
end
|
160
160
|
end
|
@@ -166,7 +166,7 @@ describe 'ActiveRecord mixin' do
|
|
166
166
|
|
167
167
|
it 'should index all instances' do
|
168
168
|
Post.reindex(:batch_size => nil)
|
169
|
-
Sunspot
|
169
|
+
Sunspot.commit
|
170
170
|
Post.search.results.to_set.should == @posts.to_set
|
171
171
|
end
|
172
172
|
|
@@ -175,7 +175,7 @@ describe 'ActiveRecord mixin' do
|
|
175
175
|
old_post.index!
|
176
176
|
old_post.destroy
|
177
177
|
Post.reindex
|
178
|
-
Sunspot
|
178
|
+
Sunspot.commit
|
179
179
|
Post.search.results.to_set.should == @posts.to_set
|
180
180
|
end
|
181
181
|
|
@@ -188,7 +188,7 @@ describe 'ActiveRecord mixin' do
|
|
188
188
|
|
189
189
|
it 'should index all instances' do
|
190
190
|
Post.reindex(:batch_size => nil)
|
191
|
-
Sunspot
|
191
|
+
Sunspot.commit
|
192
192
|
Post.search.results.to_set.should == @posts.to_set
|
193
193
|
end
|
194
194
|
|
@@ -197,14 +197,14 @@ describe 'ActiveRecord mixin' do
|
|
197
197
|
old_post.index!
|
198
198
|
old_post.destroy
|
199
199
|
Post.reindex
|
200
|
-
Sunspot
|
200
|
+
Sunspot.commit
|
201
201
|
Post.search.results.to_set.should == @posts.to_set
|
202
202
|
end
|
203
203
|
|
204
204
|
describe "using batch sizes" do
|
205
205
|
it 'should index with a specified batch size' do
|
206
206
|
Post.reindex(:batch_size => 1)
|
207
|
-
Sunspot
|
207
|
+
Sunspot.commit
|
208
208
|
Post.search.results.to_set.should == @posts.to_set
|
209
209
|
end
|
210
210
|
end
|
@@ -263,12 +263,12 @@ describe 'ActiveRecord mixin' do
|
|
263
263
|
end
|
264
264
|
|
265
265
|
it "should commit after indexing each batch" do
|
266
|
-
Sunspot
|
266
|
+
Sunspot.should_receive(:commit).twice
|
267
267
|
Post.reindex(:batch_size => 5)
|
268
268
|
end
|
269
269
|
|
270
270
|
it "should commit after indexing everything" do
|
271
|
-
Sunspot
|
271
|
+
Sunspot.should_receive(:commit).once
|
272
272
|
Post.reindex(:batch_commit => false)
|
273
273
|
end
|
274
274
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sunspot_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mat Brown
|
@@ -12,7 +12,7 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date: 2009-10-
|
15
|
+
date: 2009-10-17 00:00:00 -04:00
|
16
16
|
default_executable:
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
@@ -125,12 +125,10 @@ files:
|
|
125
125
|
- spec/mock_app/config/initializers/session_store.rb
|
126
126
|
- spec/mock_app/config/routes.rb
|
127
127
|
- spec/mock_app/config/sunspot.yml
|
128
|
-
- spec/mock_app/db/test.db
|
129
128
|
- spec/model_lifecycle_spec.rb
|
130
129
|
- spec/model_spec.rb
|
131
130
|
- spec/request_lifecycle_spec.rb
|
132
131
|
- spec/schema.rb
|
133
|
-
- spec/session_spec.rb
|
134
132
|
- spec/spec_helper.rb
|
135
133
|
has_rdoc: true
|
136
134
|
homepage: http://github.com/outoftime/sunspot_rails
|
@@ -156,28 +154,27 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
154
|
requirements: []
|
157
155
|
|
158
156
|
rubyforge_project: sunspot
|
159
|
-
rubygems_version: 1.3.
|
157
|
+
rubygems_version: 1.3.5
|
160
158
|
signing_key:
|
161
159
|
specification_version: 3
|
162
160
|
summary: Rails integration for the Sunspot Solr search library
|
163
161
|
test_files:
|
164
|
-
- spec/spec_helper.rb
|
165
|
-
- spec/session_spec.rb
|
166
162
|
- spec/configuration_spec.rb
|
167
|
-
- spec/model_lifecycle_spec.rb
|
168
|
-
- spec/schema.rb
|
169
|
-
- spec/model_spec.rb
|
170
|
-
- spec/mock_app/app/controllers/posts_controller.rb
|
171
|
-
- spec/mock_app/app/controllers/application_controller.rb
|
172
163
|
- spec/mock_app/app/controllers/application.rb
|
164
|
+
- spec/mock_app/app/controllers/application_controller.rb
|
165
|
+
- spec/mock_app/app/controllers/posts_controller.rb
|
173
166
|
- spec/mock_app/app/models/blog.rb
|
174
|
-
- spec/mock_app/app/models/post_with_auto.rb
|
175
167
|
- spec/mock_app/app/models/post.rb
|
168
|
+
- spec/mock_app/app/models/post_with_auto.rb
|
169
|
+
- spec/mock_app/config/boot.rb
|
176
170
|
- spec/mock_app/config/environment.rb
|
177
|
-
- spec/mock_app/config/initializers/session_store.rb
|
178
|
-
- spec/mock_app/config/initializers/new_rails_defaults.rb
|
179
171
|
- spec/mock_app/config/environments/development.rb
|
180
172
|
- spec/mock_app/config/environments/test.rb
|
173
|
+
- spec/mock_app/config/initializers/new_rails_defaults.rb
|
174
|
+
- spec/mock_app/config/initializers/session_store.rb
|
181
175
|
- spec/mock_app/config/routes.rb
|
182
|
-
- spec/
|
176
|
+
- spec/model_lifecycle_spec.rb
|
177
|
+
- spec/model_spec.rb
|
183
178
|
- spec/request_lifecycle_spec.rb
|
179
|
+
- spec/schema.rb
|
180
|
+
- spec/spec_helper.rb
|
data/spec/mock_app/db/test.db
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
S
|
data/spec/session_spec.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
-
|
3
|
-
describe 'Sunspot::Rails session' do
|
4
|
-
it 'should be a different object for each thread' do
|
5
|
-
session1 = nil
|
6
|
-
session2 = nil
|
7
|
-
Thread.new { session1 = Sunspot::Rails.session }.join
|
8
|
-
Thread.new { session2 = Sunspot::Rails.session }.join
|
9
|
-
session1.should_not eql(session2)
|
10
|
-
end
|
11
|
-
end
|