sunspot_rails 0.10.5 → 0.10.7
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 +2 -2
- data/dev_tasks/gemspec.rake +17 -3
- data/lib/sunspot/rails/request_lifecycle.rb +1 -1
- data/lib/sunspot/rails/searchable.rb +12 -16
- data/lib/sunspot/rails/tasks.rb +2 -2
- data/lib/sunspot/rails.rb +13 -0
- data/rails/init.rb +0 -4
- data/spec/mock_app/db/test.db +1 -0
- data/spec/model_lifecycle_spec.rb +3 -3
- data/spec/model_spec.rb +18 -18
- data/spec/session_spec.rb +11 -0
- data/spec/spec_helper.rb +2 -2
- metadata +16 -17
- data/TODO +0 -4
data/VERSION.yml
CHANGED
data/dev_tasks/gemspec.rake
CHANGED
@@ -6,7 +6,14 @@ begin
|
|
6
6
|
s.summary = 'Rails integration for the Sunspot Solr search library'
|
7
7
|
s.email = 'mat@patch.com'
|
8
8
|
s.homepage = 'http://github.com/outoftime/sunspot_rails'
|
9
|
-
s.description =
|
9
|
+
s.description = <<TEXT
|
10
|
+
Sunspot::Rails is an extension to the Sunspot library for Solr search.
|
11
|
+
Sunspot::Rails adds integration between Sunspot and ActiveRecord, including
|
12
|
+
defining search and indexing related methods on ActiveRecord models themselves,
|
13
|
+
running a Sunspot-compatible Solr instance for development and test
|
14
|
+
environments, and automatically commit Solr index changes at the end of each
|
15
|
+
Rails request.
|
16
|
+
TEXT
|
10
17
|
s.authors = ['Mat Brown', 'Peer Allan', 'Michael Moen', 'Benjamin Krause']
|
11
18
|
s.rubyforge_project = 'sunspot'
|
12
19
|
s.files = FileList['[A-Z]*',
|
@@ -17,12 +24,19 @@ begin
|
|
17
24
|
'spec/*.rb',
|
18
25
|
'spec/mock_app/{app,lib,db,vendor,config}/**/*',
|
19
26
|
'spec/mock_app/{tmp,log,solr}']
|
20
|
-
s.add_dependency 'rails', '~> 2.1'
|
21
27
|
s.add_dependency 'escape', '>= 0.0.4'
|
22
|
-
s.add_dependency '
|
28
|
+
s.add_dependency 'sunspot', '~> 0.10.0'
|
23
29
|
s.add_development_dependency 'rspec', '~> 1.2'
|
24
30
|
s.add_development_dependency 'rspec-rails', '~> 1.2'
|
25
31
|
s.add_development_dependency 'ruby-debug', '~> 0.10'
|
26
32
|
s.add_development_dependency 'technicalpickles-jeweler', '~> 1.0'
|
27
33
|
end
|
34
|
+
|
35
|
+
Jeweler::RubyforgeTasks.new
|
36
|
+
Jeweler::GemcutterTasks.new
|
37
|
+
end
|
38
|
+
|
39
|
+
namespace :release do
|
40
|
+
desc "Release gem to RubyForge and GitHub"
|
41
|
+
task :all => [:"rubyforge:release:gem", :"gemcutter:release"]
|
28
42
|
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.commit_if_dirty if Sunspot::Rails.configuration.auto_commit_after_request?
|
12
|
+
Sunspot::Rails.session.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.search(self, &block)
|
107
|
+
Sunspot::Rails.session.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.remove_all(self)
|
128
|
+
Sunspot::Rails.session.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.commit
|
139
|
+
remove_all_from_index
|
140
|
+
Sunspot::Rails.session.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.index!(all(:include => options[:include]))
|
183
|
+
Sunspot::Rails.session.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.index(all(:include => options[:include], :offset => offset, :limit => options[:batch_size], :order => primary_key))
|
190
|
+
Sunspot::Rails.session.index(all(:include => options[:include], :offset => offset, :limit => options[:batch_size], :order => primary_key))
|
191
191
|
end
|
192
|
-
Sunspot.commit if options[:batch_commit]
|
192
|
+
Sunspot::Rails.session.commit if options[:batch_commit]
|
193
193
|
offset += options[:batch_size]
|
194
194
|
counter += 1
|
195
195
|
end
|
196
|
-
Sunspot.commit unless options[:batch_commit]
|
196
|
+
Sunspot::Rails.session.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.index(self)
|
270
|
+
Sunspot::Rails.session.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.index!(self)
|
277
|
+
Sunspot::Rails.session.index!(self)
|
278
278
|
end
|
279
279
|
|
280
280
|
#
|
@@ -285,19 +285,15 @@ module Sunspot #:nodoc:
|
|
285
285
|
# manually.
|
286
286
|
#
|
287
287
|
def remove_from_index
|
288
|
-
Sunspot.remove(self)
|
288
|
+
Sunspot::Rails.session.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
|
-
#
|
298
295
|
def remove_from_index!
|
299
|
-
Sunspot.remove(self)
|
300
|
-
Sunspot.commit
|
296
|
+
Sunspot::Rails.session.remove!(self)
|
301
297
|
end
|
302
298
|
end
|
303
299
|
end
|
data/lib/sunspot/rails/tasks.rb
CHANGED
@@ -16,7 +16,7 @@ namespace :sunspot do
|
|
16
16
|
[data_path, pid_path].each { |path| FileUtils.mkdir_p(path) }
|
17
17
|
port = Sunspot::Rails.configuration.port
|
18
18
|
FileUtils.cd(File.join(pid_path)) do
|
19
|
-
command = ['sunspot-solr', 'start', '
|
19
|
+
command = ['sunspot-solr', 'start', '-p', port.to_s, '-d', data_path]
|
20
20
|
if solr_home
|
21
21
|
command << '-s' << solr_home
|
22
22
|
end
|
@@ -33,7 +33,7 @@ namespace :sunspot do
|
|
33
33
|
end
|
34
34
|
FileUtils.mkdir_p(data_path)
|
35
35
|
port = Sunspot::Rails.configuration.port
|
36
|
-
command = ['sunspot-solr', 'run', '
|
36
|
+
command = ['sunspot-solr', 'run', '-p', port.to_s, '-d', data_path]
|
37
37
|
if RUBY_PLATFORM =~ /w(in)?32$/
|
38
38
|
command.first << '.bat'
|
39
39
|
end
|
data/lib/sunspot/rails.rb
CHANGED
@@ -8,6 +8,19 @@ 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
|
11
24
|
end
|
12
25
|
end
|
13
26
|
end
|
data/rails/init.rb
CHANGED
@@ -1,9 +1,5 @@
|
|
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
|
-
|
7
3
|
Sunspot::Adapters::InstanceAdapter.register(Sunspot::Rails::Adapters::ActiveRecordInstanceAdapter, ActiveRecord::Base)
|
8
4
|
Sunspot::Adapters::DataAccessor.register(Sunspot::Rails::Adapters::ActiveRecordDataAccessor, ActiveRecord::Base)
|
9
5
|
ActiveRecord::Base.module_eval { include(Sunspot::Rails::Searchable) }
|
@@ -0,0 +1 @@
|
|
1
|
+
S
|
@@ -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.commit
|
7
|
+
Sunspot::Rails.session.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.commit
|
19
|
+
Sunspot::Rails.session.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.commit
|
31
|
+
Sunspot::Rails.session.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.commit
|
15
|
+
Sunspot::Rails.session.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.commit
|
43
|
+
Sunspot::Rails.session.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.index(post) }
|
63
|
-
Sunspot.commit
|
62
|
+
@posts = Array.new(10) { Post.create! }.each { |post| Sunspot::Rails.session.index(post) }
|
63
|
+
Sunspot::Rails.session.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.commit
|
72
|
+
Sunspot::Rails.session.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.index(post) }
|
80
|
-
Sunspot.commit
|
79
|
+
Array.new(10) { Post.create! }.each { |post| Sunspot::Rails.session.index(post) }
|
80
|
+
Sunspot::Rails.session.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.commit
|
118
|
+
Sunspot::Rails.session.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.commit
|
139
|
+
Sunspot::Rails.session.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.commit
|
151
|
+
Sunspot::Rails.session.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.commit
|
157
|
+
Sunspot::Rails.session.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.commit
|
169
|
+
Sunspot::Rails.session.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.commit
|
178
|
+
Sunspot::Rails.session.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.commit
|
191
|
+
Sunspot::Rails.session.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.commit
|
200
|
+
Sunspot::Rails.session.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.commit
|
207
|
+
Sunspot::Rails.session.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.should_receive(:commit).twice
|
266
|
+
Sunspot::Rails.session.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.should_receive(:commit).once
|
271
|
+
Sunspot::Rails.session.should_receive(:commit).once
|
272
272
|
Post.reindex(:batch_commit => false)
|
273
273
|
end
|
274
274
|
|
@@ -0,0 +1,11 @@
|
|
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
|
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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mat Brown
|
@@ -12,19 +12,9 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date: 2009-
|
15
|
+
date: 2009-10-12 00:00:00 -04:00
|
16
16
|
default_executable:
|
17
17
|
dependencies:
|
18
|
-
- !ruby/object:Gem::Dependency
|
19
|
-
name: rails
|
20
|
-
type: :runtime
|
21
|
-
version_requirement:
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ~>
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: "2.1"
|
27
|
-
version:
|
28
18
|
- !ruby/object:Gem::Dependency
|
29
19
|
name: escape
|
30
20
|
type: :runtime
|
@@ -36,14 +26,14 @@ dependencies:
|
|
36
26
|
version: 0.0.4
|
37
27
|
version:
|
38
28
|
- !ruby/object:Gem::Dependency
|
39
|
-
name:
|
29
|
+
name: sunspot
|
40
30
|
type: :runtime
|
41
31
|
version_requirement:
|
42
32
|
version_requirements: !ruby/object:Gem::Requirement
|
43
33
|
requirements:
|
44
|
-
- -
|
34
|
+
- - ~>
|
45
35
|
- !ruby/object:Gem::Version
|
46
|
-
version: 0.
|
36
|
+
version: 0.10.0
|
47
37
|
version:
|
48
38
|
- !ruby/object:Gem::Dependency
|
49
39
|
name: rspec
|
@@ -85,7 +75,14 @@ dependencies:
|
|
85
75
|
- !ruby/object:Gem::Version
|
86
76
|
version: "1.0"
|
87
77
|
version:
|
88
|
-
description:
|
78
|
+
description: |
|
79
|
+
Sunspot::Rails is an extension to the Sunspot library for Solr search.
|
80
|
+
Sunspot::Rails adds integration between Sunspot and ActiveRecord, including
|
81
|
+
defining search and indexing related methods on ActiveRecord models themselves,
|
82
|
+
running a Sunspot-compatible Solr instance for development and test
|
83
|
+
environments, and automatically commit Solr index changes at the end of each
|
84
|
+
Rails request.
|
85
|
+
|
89
86
|
email: mat@patch.com
|
90
87
|
executables: []
|
91
88
|
|
@@ -99,7 +96,6 @@ files:
|
|
99
96
|
- MIT-LICENSE
|
100
97
|
- README.rdoc
|
101
98
|
- Rakefile
|
102
|
-
- TODO
|
103
99
|
- VERSION.yml
|
104
100
|
- dev_tasks/gemspec.rake
|
105
101
|
- dev_tasks/rdoc.rake
|
@@ -129,10 +125,12 @@ files:
|
|
129
125
|
- spec/mock_app/config/initializers/session_store.rb
|
130
126
|
- spec/mock_app/config/routes.rb
|
131
127
|
- spec/mock_app/config/sunspot.yml
|
128
|
+
- spec/mock_app/db/test.db
|
132
129
|
- spec/model_lifecycle_spec.rb
|
133
130
|
- spec/model_spec.rb
|
134
131
|
- spec/request_lifecycle_spec.rb
|
135
132
|
- spec/schema.rb
|
133
|
+
- spec/session_spec.rb
|
136
134
|
- spec/spec_helper.rb
|
137
135
|
has_rdoc: true
|
138
136
|
homepage: http://github.com/outoftime/sunspot_rails
|
@@ -164,6 +162,7 @@ specification_version: 3
|
|
164
162
|
summary: Rails integration for the Sunspot Solr search library
|
165
163
|
test_files:
|
166
164
|
- spec/spec_helper.rb
|
165
|
+
- spec/session_spec.rb
|
167
166
|
- spec/configuration_spec.rb
|
168
167
|
- spec/model_lifecycle_spec.rb
|
169
168
|
- spec/schema.rb
|