sunspot 2.2.4 → 2.2.5
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.
- checksums.yaml +4 -4
- data/lib/sunspot/configuration.rb +2 -1
- data/lib/sunspot/query/more_like_this.rb +1 -1
- data/lib/sunspot/session.rb +23 -22
- data/lib/sunspot/session_proxy/thread_local_session_proxy.rb +3 -3
- data/lib/sunspot/version.rb +1 -1
- data/spec/api/query/more_like_this_spec.rb +1 -1
- data/spec/api/session_proxy/thread_local_session_proxy_spec.rb +36 -26
- data/spec/api/session_spec.rb +12 -6
- data/sunspot.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddf4e1e101c7789cbba01b5d4a46d69ac295f0e3
|
4
|
+
data.tar.gz: ef751e6cb93dbdd4bda40b18b661e044cee927fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2dd0adb2ce792ce3fa11ebbf9c05d7043e3402ba946e06a8b2ac78d84e885dc6cdda942528804f674e219d08ac1555e44fd392f8d993dd7feb4b24725e2368a6
|
7
|
+
data.tar.gz: feaeaa4d3d41676e5d063dad39cccbf1bca1ebe6968e9f952037e9b362886f76f1f8b2e7118078ee4335435da39c5b6f4e1e3323faab0d1eb636836863c5d123
|
@@ -25,6 +25,7 @@ module Sunspot
|
|
25
25
|
url 'http://127.0.0.1:8983/solr/default'
|
26
26
|
read_timeout nil
|
27
27
|
open_timeout nil
|
28
|
+
proxy nil
|
28
29
|
end
|
29
30
|
master_solr do
|
30
31
|
url nil
|
@@ -37,7 +38,7 @@ module Sunspot
|
|
37
38
|
end
|
38
39
|
end
|
39
40
|
end
|
40
|
-
|
41
|
+
|
41
42
|
# Location for the default solr configuration files,
|
42
43
|
# required for bootstrapping a new solr installation
|
43
44
|
#
|
@@ -50,7 +50,7 @@ module Sunspot
|
|
50
50
|
params[:"mlt.fl"] = @fields.keys.join(",")
|
51
51
|
boosted_fields = @fields.values.select { |field| field.boost }
|
52
52
|
unless boosted_fields.empty?
|
53
|
-
params[:qf] = boosted_fields.map do |field|
|
53
|
+
params[:"mlt.qf"] = boosted_fields.map do |field|
|
54
54
|
field.to_boosted_field
|
55
55
|
end.join(' ')
|
56
56
|
end
|
data/lib/sunspot/session.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Sunspot
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# A Sunspot session encapsulates a connection to Solr and a set of
|
4
4
|
# configuration choices. Though users of Sunspot may manually instantiate
|
5
5
|
# Session objects, in the general case it's easier to use the singleton
|
@@ -10,8 +10,8 @@ module Sunspot
|
|
10
10
|
class Session
|
11
11
|
class <<self
|
12
12
|
attr_writer :connection_class #:nodoc:
|
13
|
-
|
14
|
-
#
|
13
|
+
|
14
|
+
#
|
15
15
|
# For testing purposes
|
16
16
|
#
|
17
17
|
def connection_class #:nodoc:
|
@@ -19,12 +19,12 @@ module Sunspot
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
#
|
22
|
+
#
|
23
23
|
# Sunspot::Configuration object for this session
|
24
24
|
#
|
25
25
|
attr_reader :config
|
26
26
|
|
27
|
-
#
|
27
|
+
#
|
28
28
|
# Sessions are initialized with a Sunspot configuration and a Solr
|
29
29
|
# connection. Usually you will want to stick with the default arguments
|
30
30
|
# when instantiating your own sessions.
|
@@ -36,7 +36,7 @@ module Sunspot
|
|
36
36
|
@deletes = @adds = 0
|
37
37
|
end
|
38
38
|
|
39
|
-
#
|
39
|
+
#
|
40
40
|
# See Sunspot.new_search
|
41
41
|
#
|
42
42
|
def new_search(*types, &block)
|
@@ -59,7 +59,7 @@ module Sunspot
|
|
59
59
|
search.execute
|
60
60
|
end
|
61
61
|
|
62
|
-
#
|
62
|
+
#
|
63
63
|
# See Sunspot.new_more_like_this
|
64
64
|
#
|
65
65
|
def new_more_like_this(object, *types, &block)
|
@@ -91,7 +91,7 @@ module Sunspot
|
|
91
91
|
indexer.add(objects)
|
92
92
|
end
|
93
93
|
|
94
|
-
#
|
94
|
+
#
|
95
95
|
# See Sunspot.index!
|
96
96
|
#
|
97
97
|
def index!(*objects)
|
@@ -131,7 +131,7 @@ module Sunspot
|
|
131
131
|
connection.optimize
|
132
132
|
end
|
133
133
|
|
134
|
-
#
|
134
|
+
#
|
135
135
|
# See Sunspot.remove
|
136
136
|
#
|
137
137
|
def remove(*objects, &block)
|
@@ -155,7 +155,7 @@ module Sunspot
|
|
155
155
|
end
|
156
156
|
end
|
157
157
|
|
158
|
-
#
|
158
|
+
#
|
159
159
|
# See Sunspot.remove!
|
160
160
|
#
|
161
161
|
def remove!(*objects, &block)
|
@@ -163,7 +163,7 @@ module Sunspot
|
|
163
163
|
commit
|
164
164
|
end
|
165
165
|
|
166
|
-
#
|
166
|
+
#
|
167
167
|
# See Sunspot.remove_by_id
|
168
168
|
#
|
169
169
|
def remove_by_id(clazz, *ids)
|
@@ -176,7 +176,7 @@ module Sunspot
|
|
176
176
|
indexer.remove_by_id(class_name, ids)
|
177
177
|
end
|
178
178
|
|
179
|
-
#
|
179
|
+
#
|
180
180
|
# See Sunspot.remove_by_id!
|
181
181
|
#
|
182
182
|
def remove_by_id!(clazz, *ids)
|
@@ -198,7 +198,7 @@ module Sunspot
|
|
198
198
|
end
|
199
199
|
end
|
200
200
|
|
201
|
-
#
|
201
|
+
#
|
202
202
|
# See Sunspot.remove_all!
|
203
203
|
#
|
204
204
|
def remove_all!(*classes)
|
@@ -206,35 +206,35 @@ module Sunspot
|
|
206
206
|
commit
|
207
207
|
end
|
208
208
|
|
209
|
-
#
|
209
|
+
#
|
210
210
|
# See Sunspot.dirty?
|
211
211
|
#
|
212
212
|
def dirty?
|
213
213
|
(@deletes + @adds) > 0
|
214
214
|
end
|
215
215
|
|
216
|
-
#
|
216
|
+
#
|
217
217
|
# See Sunspot.commit_if_dirty
|
218
218
|
#
|
219
219
|
def commit_if_dirty(soft_commit = false)
|
220
220
|
commit soft_commit if dirty?
|
221
221
|
end
|
222
|
-
|
223
|
-
#
|
222
|
+
|
223
|
+
#
|
224
224
|
# See Sunspot.delete_dirty?
|
225
225
|
#
|
226
226
|
def delete_dirty?
|
227
227
|
@deletes > 0
|
228
228
|
end
|
229
229
|
|
230
|
-
#
|
230
|
+
#
|
231
231
|
# See Sunspot.commit_if_delete_dirty
|
232
232
|
#
|
233
233
|
def commit_if_delete_dirty(soft_commit = false)
|
234
234
|
commit soft_commit if delete_dirty?
|
235
235
|
end
|
236
|
-
|
237
|
-
#
|
236
|
+
|
237
|
+
#
|
238
238
|
# See Sunspot.batch
|
239
239
|
#
|
240
240
|
def batch
|
@@ -245,7 +245,7 @@ module Sunspot
|
|
245
245
|
|
246
246
|
private
|
247
247
|
|
248
|
-
#
|
248
|
+
#
|
249
249
|
# Retrieve the Solr connection for this session, creating one if it does not
|
250
250
|
# already exist.
|
251
251
|
#
|
@@ -257,7 +257,8 @@ module Sunspot
|
|
257
257
|
@connection ||=
|
258
258
|
self.class.connection_class.connect(:url => config.solr.url,
|
259
259
|
:read_timeout => config.solr.read_timeout,
|
260
|
-
:open_timeout => config.solr.open_timeout
|
260
|
+
:open_timeout => config.solr.open_timeout,
|
261
|
+
:proxy => config.solr.proxy)
|
261
262
|
end
|
262
263
|
|
263
264
|
def indexer
|
@@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), 'abstract_session_proxy')
|
|
3
3
|
|
4
4
|
module Sunspot
|
5
5
|
module SessionProxy
|
6
|
-
#
|
6
|
+
#
|
7
7
|
# This class implements a session proxy that creates a different Session
|
8
8
|
# object for each thread. Any multithreaded application should use this
|
9
9
|
# proxy.
|
@@ -21,12 +21,12 @@ module Sunspot
|
|
21
21
|
:new_search, :optimize, :remove, :remove!, :remove_all, :remove_all!, :remove_by_id, :remove_by_id!,
|
22
22
|
:search, :more_like_this, :new_more_like_this, :atomic_update, :atomic_update!, :to => :session
|
23
23
|
|
24
|
-
#
|
24
|
+
#
|
25
25
|
# Optionally pass an existing Sunspot::Configuration object. If none is
|
26
26
|
# passed, a default configuration is used; it can then be modified using
|
27
27
|
# the #config attribute.
|
28
28
|
#
|
29
|
-
def initialize(config = Sunspot::Configuration.
|
29
|
+
def initialize(config = Sunspot::Configuration.build)
|
30
30
|
@config = config
|
31
31
|
ObjectSpace.define_finalizer(self, FINALIZER)
|
32
32
|
end
|
data/lib/sunspot/version.rb
CHANGED
@@ -36,7 +36,7 @@ describe 'more_like_this' do
|
|
36
36
|
fields :body, :tags => 8
|
37
37
|
end
|
38
38
|
connection.searches.last[:"mlt.fl"].split(',').sort.should == %w(body_textsv tags_textv)
|
39
|
-
connection.should have_last_search_with(:qf => "tags_textv^8")
|
39
|
+
connection.should have_last_search_with(:"mlt.qf" => "tags_textv^8")
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'doesn\'t assign boosts to fields when not specified' do
|
@@ -2,38 +2,48 @@ require File.expand_path('spec_helper', File.dirname(__FILE__))
|
|
2
2
|
require 'weakref'
|
3
3
|
|
4
4
|
describe Sunspot::SessionProxy::ThreadLocalSessionProxy do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
context 'when not passing a config' do
|
6
|
+
before :each do
|
7
|
+
@proxy = Sunspot::SessionProxy::ThreadLocalSessionProxy.new
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
@proxy.session.should eql(@proxy.session)
|
10
|
+
it_should_behave_like 'session proxy'
|
12
11
|
end
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end.join
|
20
|
-
session1.should_not eql(session2)
|
21
|
-
end
|
13
|
+
context 'when passing a config' do
|
14
|
+
before :each do
|
15
|
+
@config = Sunspot::Configuration.build
|
16
|
+
@proxy = Sunspot::SessionProxy::ThreadLocalSessionProxy.new(@config)
|
17
|
+
end
|
22
18
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
19
|
+
it 'should have the same session for the same thread' do
|
20
|
+
@proxy.session.should eql(@proxy.session)
|
21
|
+
end
|
27
22
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
it 'should not have the same session for different threads' do
|
24
|
+
session1 = @proxy.session
|
25
|
+
session2 = nil
|
26
|
+
Thread.new do
|
27
|
+
session2 = @proxy.session
|
28
|
+
end.join
|
29
|
+
session1.should_not eql(session2)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should not have the same session for the same thread in different proxy instances' do
|
33
|
+
proxy2 = Sunspot::SessionProxy::ThreadLocalSessionProxy.new(@config)
|
34
|
+
@proxy.session.should_not eql(proxy2.session)
|
35
|
+
end
|
36
|
+
|
37
|
+
(Sunspot::Session.public_instance_methods(false) - ['config', :config]).each do |method|
|
38
|
+
it "should delegate #{method.inspect} to its session" do
|
39
|
+
args = Array.new(Sunspot::Session.instance_method(method).arity.abs) do
|
40
|
+
stub('arg')
|
41
|
+
end
|
42
|
+
@proxy.session.should_receive(method).with(*args)
|
43
|
+
@proxy.send(method, *args)
|
32
44
|
end
|
33
|
-
@proxy.session.should_receive(method).with(*args)
|
34
|
-
@proxy.send(method, *args)
|
35
45
|
end
|
36
|
-
end
|
37
46
|
|
38
|
-
|
47
|
+
it_should_behave_like 'session proxy'
|
48
|
+
end
|
39
49
|
end
|
data/spec/api/session_spec.rb
CHANGED
@@ -117,6 +117,12 @@ describe 'Session' do
|
|
117
117
|
Sunspot.commit
|
118
118
|
connection.opts[:open_timeout].should == 0.5
|
119
119
|
end
|
120
|
+
|
121
|
+
it 'should open a connection through a provided proxy' do
|
122
|
+
Sunspot.config.solr.proxy = 'http://proxy.com:1234'
|
123
|
+
Sunspot.commit
|
124
|
+
connection.opts[:proxy].should == 'http://proxy.com:1234'
|
125
|
+
end
|
120
126
|
end
|
121
127
|
|
122
128
|
context 'custom session' do
|
@@ -143,7 +149,7 @@ describe 'Session' do
|
|
143
149
|
it 'should start out not dirty' do
|
144
150
|
@session.dirty?.should be_false
|
145
151
|
end
|
146
|
-
|
152
|
+
|
147
153
|
it 'should start out not delete_dirty' do
|
148
154
|
@session.delete_dirty?.should be_false
|
149
155
|
end
|
@@ -152,7 +158,7 @@ describe 'Session' do
|
|
152
158
|
@session.index(Post.new)
|
153
159
|
@session.dirty?.should be_true
|
154
160
|
end
|
155
|
-
|
161
|
+
|
156
162
|
it 'should be not be delete_dirty after adding an item' do
|
157
163
|
@session.index(Post.new)
|
158
164
|
@session.delete_dirty?.should be_false
|
@@ -182,12 +188,12 @@ describe 'Session' do
|
|
182
188
|
@session.remove_all
|
183
189
|
@session.dirty?.should be_true
|
184
190
|
end
|
185
|
-
|
191
|
+
|
186
192
|
it 'should be delete_dirty after a global remove_all' do
|
187
193
|
@session.remove_all
|
188
194
|
@session.delete_dirty?.should be_true
|
189
195
|
end
|
190
|
-
|
196
|
+
|
191
197
|
it 'should not be dirty after a commit' do
|
192
198
|
@session.index(Post.new)
|
193
199
|
@session.commit
|
@@ -227,14 +233,14 @@ describe 'Session' do
|
|
227
233
|
@session.commit_if_dirty
|
228
234
|
connection.should have(1).commits
|
229
235
|
end
|
230
|
-
|
236
|
+
|
231
237
|
it 'should soft commit when commit_if_dirty called on dirty session' do
|
232
238
|
@session.index(Post.new)
|
233
239
|
@session.commit_if_dirty(true)
|
234
240
|
connection.should have(1).commits
|
235
241
|
connection.should have(1).soft_commits
|
236
242
|
end
|
237
|
-
|
243
|
+
|
238
244
|
it 'should hard commit when commit_if_delete_dirty called on delete_dirty session' do
|
239
245
|
@session.remove(Post.new)
|
240
246
|
@session.commit_if_delete_dirty
|
data/sunspot.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
27
27
|
s.require_paths = ["lib"]
|
28
28
|
|
29
|
-
s.add_dependency 'rsolr', '~>1.
|
29
|
+
s.add_dependency 'rsolr', '~>1.1.1'
|
30
30
|
s.add_dependency 'pr_geohash', '~>1.0'
|
31
31
|
|
32
32
|
s.add_development_dependency 'rspec', '~>2.6.0'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sunspot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mat Brown
|
@@ -29,7 +29,7 @@ authors:
|
|
29
29
|
autorequire:
|
30
30
|
bindir: bin
|
31
31
|
cert_chain: []
|
32
|
-
date: 2016-
|
32
|
+
date: 2016-03-05 00:00:00.000000000 Z
|
33
33
|
dependencies:
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: rsolr
|
@@ -37,14 +37,14 @@ dependencies:
|
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.
|
40
|
+
version: 1.1.1
|
41
41
|
type: :runtime
|
42
42
|
prerelease: false
|
43
43
|
version_requirements: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.
|
47
|
+
version: 1.1.1
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: pr_geohash
|
50
50
|
requirement: !ruby/object:Gem::Requirement
|