mwmitchell-solr 0.5.1 → 0.5.2
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/lib/solr/connection/base.rb +2 -4
- data/lib/solr.rb +5 -5
- data/test/connection_test_methods.rb +11 -5
- data/test/direct_test.rb +3 -1
- data/test/http_test.rb +3 -1
- metadata +1 -1
data/lib/solr/connection/base.rb
CHANGED
@@ -12,7 +12,6 @@ class Solr::Connection::Base
|
|
12
12
|
# Solr::Adapter::Direct (jRuby only)
|
13
13
|
def initialize(adapter, opts={})
|
14
14
|
@adapter=adapter
|
15
|
-
opts[:auto_commit]||=false
|
16
15
|
opts[:global_params]||={}
|
17
16
|
default_global_params = {
|
18
17
|
:wt=>:ruby,
|
@@ -57,10 +56,9 @@ class Solr::Connection::Base
|
|
57
56
|
# if :ruby is the :wt, then Solr::Response::Base is returned
|
58
57
|
# -- there's not really a way to figure out what kind of handler request this is.
|
59
58
|
|
60
|
-
def update(data, params={}
|
59
|
+
def update(data, params={})
|
61
60
|
params = map_params(params)
|
62
61
|
response = @adapter.update(data, params)
|
63
|
-
self.commit if auto_commit.nil? ? @opts[:auto_commit]==true : auto_commit
|
64
62
|
params[:wt]==:ruby ? Solr::Response::Update.new(response) : response
|
65
63
|
end
|
66
64
|
|
@@ -70,7 +68,7 @@ class Solr::Connection::Base
|
|
70
68
|
|
71
69
|
# send </commit>
|
72
70
|
def commit(opts={})
|
73
|
-
update message.commit, opts
|
71
|
+
update message.commit, opts
|
74
72
|
end
|
75
73
|
|
76
74
|
# send </optimize>
|
data/lib/solr.rb
CHANGED
@@ -7,7 +7,7 @@ proc {|base, files|
|
|
7
7
|
|
8
8
|
module Solr
|
9
9
|
|
10
|
-
VERSION = '0.5.
|
10
|
+
VERSION = '0.5.2'
|
11
11
|
|
12
12
|
autoload :Adapter, 'solr/adapter'
|
13
13
|
autoload :Message, 'solr/message'
|
@@ -19,16 +19,16 @@ module Solr
|
|
19
19
|
|
20
20
|
# factory for creating connections
|
21
21
|
# adapter name is either :http or :direct
|
22
|
-
#
|
23
|
-
#
|
24
|
-
def self.connect(adapter_name,
|
22
|
+
# opts are sent to the adapter instance (:url for http, :dist_dir for :direct etc.)
|
23
|
+
# and to the connection instance
|
24
|
+
def self.connect(adapter_name, opts={})
|
25
25
|
types = {
|
26
26
|
:http=>'HTTP',
|
27
27
|
:direct=>'Direct'
|
28
28
|
}
|
29
29
|
adapter_class_name = "Solr::Adapter::#{types[adapter_name]}"
|
30
30
|
adapter_class = Kernel.eval adapter_class_name
|
31
|
-
Solr::Connection::Base.new(adapter_class.new(
|
31
|
+
Solr::Connection::Base.new(adapter_class.new(opts), opts)
|
32
32
|
end
|
33
33
|
|
34
34
|
class RequestError < RuntimeError; end
|
@@ -5,10 +5,11 @@
|
|
5
5
|
|
6
6
|
module ConnectionTestMethods
|
7
7
|
|
8
|
-
def teardown
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
#def teardown
|
9
|
+
# @solr.delete_by_query('id:[* TO *]')
|
10
|
+
# @solr.commit
|
11
|
+
# assert_equal 0, @solr.query(:q=>'*:*').docs.size
|
12
|
+
#end
|
12
13
|
|
13
14
|
# setting adapter options in Solr.connect method should set them in the adapter
|
14
15
|
def test_set_adapter_options
|
@@ -18,7 +19,7 @@ module ConnectionTestMethods
|
|
18
19
|
|
19
20
|
# setting connection options in Solr.connect method should set them in the connection
|
20
21
|
def test_set_connection_options
|
21
|
-
solr = Solr.connect(:http,
|
22
|
+
solr = Solr.connect(:http, :default_wt=>:json)
|
22
23
|
assert_equal :json, solr.opts[:default_wt]
|
23
24
|
end
|
24
25
|
|
@@ -48,15 +49,18 @@ module ConnectionTestMethods
|
|
48
49
|
def test_add
|
49
50
|
assert_equal 0, @solr.query(:q=>'*:*').total
|
50
51
|
response = @solr.add(:id=>100)
|
52
|
+
@solr.commit
|
51
53
|
assert_equal 1, @solr.query(:q=>'*:*').total
|
52
54
|
assert response.is_a?(Solr::Response::Update)
|
53
55
|
end
|
54
56
|
|
55
57
|
def test_delete_by_id
|
56
58
|
@solr.add(:id=>100)
|
59
|
+
@solr.commit
|
57
60
|
total = @solr.query(:q=>'*:*').total
|
58
61
|
assert_equal 1, total
|
59
62
|
delete_response = @solr.delete_by_id(100)
|
63
|
+
@solr.commit
|
60
64
|
assert delete_response.is_a?(Solr::Response::Update)
|
61
65
|
total = @solr.query(:q=>'*:*').total
|
62
66
|
assert_equal 0, total
|
@@ -64,8 +68,10 @@ module ConnectionTestMethods
|
|
64
68
|
|
65
69
|
def test_delete_by_query
|
66
70
|
@solr.add(:id=>1, :name=>'BLAH BLAH BLAH')
|
71
|
+
@solr.commit
|
67
72
|
assert_equal 1, @solr.query(:q=>'*:*').total
|
68
73
|
response = @solr.delete_by_query('name:BLAH BLAH BLAH')
|
74
|
+
@solr.commit
|
69
75
|
assert response.is_a?(Solr::Response::Update)
|
70
76
|
assert_equal 0, @solr.query(:q=>'*:*').total
|
71
77
|
end
|
data/test/direct_test.rb
CHANGED
@@ -12,7 +12,9 @@ class DirectTest < Test::Unit::TestCase
|
|
12
12
|
base = File.expand_path( File.dirname(__FILE__) )
|
13
13
|
dist = File.join(base, '..', 'apache-solr')
|
14
14
|
home = File.join(dist, 'example', 'solr')
|
15
|
-
@solr = Solr.connect(:direct,
|
15
|
+
@solr = Solr.connect(:direct, :home_dir=>home, :dist_dir=>dist)
|
16
|
+
@solr.delete_by_query('*:*')
|
17
|
+
@solr.commit
|
16
18
|
end
|
17
19
|
|
18
20
|
end
|
data/test/http_test.rb
CHANGED