mwmitchell-rsolr 0.7.1 → 0.8.0

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.
@@ -32,8 +32,8 @@ class RSolr::HTTPClient::Adapter::NetHTTP
32
32
  full_url += url
33
33
  {
34
34
  :status_code=>net_http_response.code.to_i,
35
- :body=>net_http_response.body,
36
35
  :url=>full_url,
36
+ :body=>net_http_response.body,
37
37
  :path=>path,
38
38
  :params=>params,
39
39
  :data=>data,
data/lib/rsolr/message.rb CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  # http://builder.rubyforge.org/
3
2
  require 'rubygems'
4
3
  require 'builder'
@@ -10,13 +9,13 @@ class RSolr::Message
10
9
  class << self
11
10
 
12
11
  def xml
13
- Builder::XmlMarkup.new
12
+ ::Builder::XmlMarkup.new
14
13
  end
15
14
 
16
15
  # add({})
17
16
  # add([{}, {}])
18
17
  # add(docs) do |doc|
19
- # doc.boost = 10.0
18
+ # doc[:boost] = 10.0
20
19
  # end
21
20
  def add(data, opts={}, &block)
22
21
  data = [data] if data.respond_to?(:each_pair) # if it's a hash, put it in an array
@@ -25,11 +24,11 @@ class RSolr::Message
25
24
  add_xml.doc do |doc_xml|
26
25
  # convert keys into strings and perform an alpha sort (easier testing between ruby and jruby)
27
26
  # but probably not great for performance? whatever...
28
- sorted_items = item.inject({}) {|acc,(k,v)| acc.merge({k.to_s=>v})}
29
- sorted_items.keys.sort.each do |k|
27
+ #sorted_items = item.inject({}) {|acc,(k,v)| acc.merge({k.to_s=>v})}
28
+ item.keys.each do |k|
30
29
  doc_attrs = {:name=>k}
31
30
  yield item, doc_attrs if block_given?
32
- [sorted_items[k]].flatten.each do |v| # multiValued attributes
31
+ [item[k]].flatten.each do |v| # multiValued attributes
33
32
  doc_xml.field(v, doc_attrs)
34
33
  end
35
34
  end
@@ -1,26 +1,25 @@
1
1
  if defined?(JRUBY_VERSION)
2
-
3
- require File.join(File.dirname(__FILE__), '..', 'test_helpers')
4
-
5
- require File.join(File.dirname(__FILE__), 'test_methods')
6
-
7
- class ConnectionDirectTest < RSolrBaseTest
8
2
 
9
- include ConnectionTestMethods
3
+ require 'helper'
4
+ require 'connection/test_methods'
10
5
 
11
- def setup
12
- base = File.expand_path( File.dirname(__FILE__) )
13
- dist = File.join(base, '..', '..', 'apache-solr')
14
- home = File.join(dist, 'example', 'solr')
15
- @solr = RSolr.connect(:adapter=>:direct, :home_dir=>home, :dist_dir=>dist)
16
- @solr.delete_by_query('*:*')
17
- @solr.commit
6
+ class ConnectionDirectTest < RSolrBaseTest
7
+
8
+ include ConnectionTestMethods
9
+
10
+ def setup
11
+ base = File.expand_path( File.dirname(__FILE__) )
12
+ dist = File.join(base, '..', '..', 'apache-solr')
13
+ home = File.join(dist, 'example', 'solr')
14
+ @solr = RSolr.connect({:adapter=>:direct}, {:home_dir=>home, :dist_dir=>dist})
15
+ @solr.delete_by_query('*:*')
16
+ @solr.commit
17
+ end
18
+
19
+ def teardown
20
+ @solr.adapter.close
21
+ end
22
+
18
23
  end
19
24
 
20
- def teardown
21
- @solr.adapter.close
22
- end
23
-
24
- end
25
-
26
25
  end
@@ -1,9 +1,8 @@
1
1
  unless defined?(JRUBY_VERSION)
2
-
3
- require File.join(File.dirname(__FILE__), '..', 'test_helpers')
4
2
 
5
- require File.join(File.dirname(__FILE__), 'test_methods')
6
-
3
+ require 'helper'
4
+ require 'connection/test_methods'
5
+
7
6
  class AdapterHTTPTest < RSolrBaseTest
8
7
 
9
8
  include ConnectionTestMethods
@@ -9,99 +9,89 @@ module ConnectionTestMethods
9
9
  #def teardown
10
10
  # @solr.delete_by_query('id:[* TO *]')
11
11
  # @solr.commit
12
- # assert_equal 0, @solr.query(:q=>'*:*').docs.size
12
+ # assert_equal 0, @solr.select(:q=>'*:*').docs.size
13
13
  #end
14
14
 
15
- # setting connection options in Solr.connect method should set them in the connection
16
- def test_set_connection_options
17
- solr = RSolr.connect(:default_wt=>:json)
18
- assert_equal :json, solr.opts[:default_wt]
19
- end
20
-
21
- # If :wt is NOT :ruby, the format doesn't get wrapped in a Solr::Response class
15
+ # If :wt is NOT :ruby, the format doesn't get converted into a Mash (special Hash; see lib/mash.rb)
22
16
  # Raw ruby can be returned by using :wt=>'ruby', not :ruby
23
17
  def test_raw_response_formats
24
- ruby_response = @solr.query(:q=>'*:*', :wt=>'ruby')
25
- assert ruby_response[:body].is_a?(String)
26
- assert ruby_response[:body]=~%r('wt'=>'ruby')
18
+ ruby_response = @solr.select(:q=>'*:*', :wt=>'ruby')
19
+ assert ruby_response.is_a?(String)
20
+ assert ruby_response =~ %r('wt'=>'ruby')
27
21
  # xml?
28
- xml_response = @solr.query(:q=>'*:*', :wt=>'xml')
29
- assert xml_response[:body]=~%r(<str name="wt">xml</str>)
22
+ xml_response = @solr.select(:q=>'*:*', :wt=>'xml')
23
+ assert xml_response.is_a?(String)
24
+ assert xml_response =~ %r(<str name="wt">xml</str>)
30
25
  # json?
31
- json_response = @solr.query(:q=>'*:*', :wt=>'json')
32
- assert json_response[:body]=~%r("wt":"json")
26
+ json_response = @solr.select(:q=>'*:*', :wt=>'json')
27
+ assert json_response.is_a?(String)
28
+ assert json_response =~ %r("wt":"json")
33
29
  end
34
30
 
35
- def test_query_responses
36
- r = @solr.query(:q=>'*:*')
37
- assert r.is_a?(RSolr::Response::Query::Base)
38
- # catch exceptions for bad queries
31
+ def test_raise_on_invalid_query
39
32
  assert_raise RSolr::RequestError do
40
- @solr.query(:q=>'!')
33
+ @solr.select(:q=>'!')
41
34
  end
42
35
  end
43
36
 
44
- def test_query_response_docs
37
+ def test_select_response_docs
45
38
  @solr.add(:id=>1, :price=>1.00, :cat=>['electronics', 'something else'])
46
39
  @solr.commit
47
- r = @solr.query(:q=>'*:*')
48
- assert r.is_a?(RSolr::Response::Query::Base)
49
- assert_equal Array, r.docs.class
50
- first = r.docs.first
40
+ r = @solr.select(:q=>'*:*')
41
+ assert r.is_a?(Mash)
51
42
 
52
- # test the has? method
53
- assert first.has?('price', 1.00)
54
- assert ! first.has?('price', 10.00)
55
- assert first.has?('cat', 'electronics')
56
- assert first.has?('cat', 'something else')
57
- assert first.has?(:cat, 'something else')
43
+ docs = r[:response][:docs]
44
+ assert_equal Array, docs.class
45
+ first = docs.first
58
46
 
59
- assert first.has?('cat', /something/)
47
+ # test the has? method
48
+ assert_equal 1.00, first[:price]
60
49
 
61
- # has? only works with strings at this time
62
- assert first.has?(:cat)
50
+ assert_equal Array, first[:cat].class
51
+ assert first[:cat].include?('electronics')
52
+ assert first[:cat].include?('something else')
53
+ assert first[:cat].include?('something else')
63
54
 
64
- assert false == first.has?('cat', /zxcv/)
65
55
  end
66
56
 
67
57
  def test_add
68
- assert_equal 0, @solr.query(:q=>'*:*').total
58
+ assert_equal 0, @solr.select(:q=>'*:*')[:response][:numFound]
69
59
  update_response = @solr.add(:id=>100)
70
- assert update_response.is_a?(RSolr::Response::Update)
60
+ assert update_response.is_a?(Mash)
71
61
  #
72
62
  @solr.commit
73
- assert_equal 1, @solr.query(:q=>'*:*').total
63
+ assert_equal 1, @solr.select(:q=>'*:*')[:response][:numFound]
74
64
  end
75
65
 
76
66
  def test_delete_by_id
77
67
  @solr.add(:id=>100)
78
68
  @solr.commit
79
- total = @solr.query(:q=>'*:*').total
69
+ total = @solr.select(:q=>'*:*')[:response][:numFound]
80
70
  assert_equal 1, total
81
71
  delete_response = @solr.delete_by_id(100)
82
72
  @solr.commit
83
- assert delete_response.is_a?(RSolr::Response::Update)
84
- total = @solr.query(:q=>'*:*').total
73
+ assert delete_response.is_a?(Mash)
74
+ total = @solr.select(:q=>'*:*')[:response][:numFound]
85
75
  assert_equal 0, total
86
76
  end
87
77
 
88
78
  def test_delete_by_query
89
79
  @solr.add(:id=>1, :name=>'BLAH BLAH BLAH')
90
80
  @solr.commit
91
- assert_equal 1, @solr.query(:q=>'*:*').total
81
+ assert_equal 1, @solr.select(:q=>'*:*')[:response][:numFound]
92
82
  response = @solr.delete_by_query('name:BLAH BLAH BLAH')
93
83
  @solr.commit
94
- assert response.is_a?(RSolr::Response::Update)
95
- assert_equal 0, @solr.query(:q=>'*:*').total
84
+ assert response.is_a?(Mash)
85
+ assert_equal 0, @solr.select(:q=>'*:*')[:response][:numFound]
96
86
  end
97
87
 
98
- def test_index_info
99
- response = @solr.index_info
100
- assert response.is_a?(RSolr::Response::IndexInfo)
88
+ def test_admin_luke_index_info
89
+ response = @solr.send_request('/admin/luke', :numTerms=>0)
90
+ assert response.is_a?(Mash)
101
91
  # make sure the ? methods are true/false
102
- assert [true, false].include?(response.current?)
103
- assert [true, false].include?(response.optimized?)
104
- assert [true, false].include?(response.has_deletions?)
92
+ assert [true, false].include?(response[:index][:current])
93
+ assert [true, false].include?(response[:index][:optimized])
94
+ assert [true, false].include?(response[:index][:hasDeletions])
105
95
  end
106
96
 
107
97
  end
@@ -2,14 +2,13 @@
2
2
  # the curb gem is a c extension based gem, jruby has no support for this
3
3
  unless defined?(JRUBY_VERSION)
4
4
 
5
- require File.join(File.dirname(__FILE__), '..', 'test_helpers')
6
-
7
- require File.join(File.dirname(__FILE__), 'test_methods')
5
+ require 'helper'
6
+ require 'http_client/test_methods'
8
7
 
9
8
  class CurbTest < RSolrBaseTest
10
9
 
11
10
  def setup
12
- @c ||= RSolr::HTTPClient.connect(URL, :curb)
11
+ @c ||= RSolr::HTTPClient::Connector.new(:curb).connect(URL)
13
12
  end
14
13
 
15
14
  include HTTPClientTestMethods
@@ -1,11 +1,10 @@
1
- require File.join(File.dirname(__FILE__), '..', 'test_helpers')
2
-
3
- require File.join(File.dirname(__FILE__), 'test_methods')
1
+ require 'helper'
2
+ require 'http_client/test_methods'
4
3
 
5
4
  class NetHTTPTest < RSolrBaseTest
6
5
 
7
6
  def setup
8
- @c ||= RSolr::HTTPClient.connect(URL, :net_http)
7
+ @c ||= RSolr::HTTPClient::Connector.new(:net_http).connect(URL)
9
8
  end
10
9
 
11
10
  include HTTPClientTestMethods
@@ -4,7 +4,7 @@ module HTTPClientTestMethods
4
4
 
5
5
  def test_raise_unknown_adapter
6
6
  assert_raise RSolr::HTTPClient::UnkownAdapterError do
7
- c = RSolr::HTTPClient.connect(URL, :blah)
7
+ c = RSolr::HTTPClient::Connector.new(:blah).connect(URL)
8
8
  end
9
9
  end
10
10
 
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), '..', 'test_helpers')
1
+ require 'helper'
2
2
 
3
3
  class HTTPUtilTest < RSolrBaseTest
4
4
 
data/test/message_test.rb CHANGED
@@ -1,4 +1,5 @@
1
- require File.join(File.dirname(__FILE__), 'test_helpers')
1
+
2
+ require 'helper'
2
3
 
3
4
  class MessageTest < RSolrBaseTest
4
5
 
@@ -52,9 +53,8 @@ class MessageTest < RSolrBaseTest
52
53
  :id=>1,
53
54
  :name=>'matt'
54
55
  }
55
-
56
- expected = '<add><doc><field name="id">1</field><field name="name">matt</field></doc></add>'
57
- assert_equal expected, RSolr::Message.add(data).to_s
56
+ assert RSolr::Message.add(data).to_s =~ /<field name="name">matt<\/field>/
57
+ assert RSolr::Message.add(data).to_s =~ /<field name="id">1<\/field>/
58
58
  end
59
59
 
60
60
  # add an array of hashes
@@ -73,7 +73,8 @@ class MessageTest < RSolrBaseTest
73
73
  message = RSolr::Message.add(data)
74
74
  expected = '<add><doc><field name="id">1</field><field name="name">matt</field></doc><doc><field name="id">2</field><field name="name">sam</field></doc></add>'
75
75
 
76
- assert_equal expected, message.to_s
76
+ assert message.to_s=~/<field name="name">matt<\/field>/
77
+ assert message.to_s=~/<field name="name">sam<\/field>/
77
78
  end
78
79
 
79
80
  # multiValue field support test, thanks to Fouad Mardini!
@@ -82,8 +83,8 @@ class MessageTest < RSolrBaseTest
82
83
  :id => 1,
83
84
  :name => ['matt1', 'matt2']
84
85
  }
85
- expected = '<add><doc><field name="id">1</field><field name="name">matt1</field><field name="name">matt2</field></doc></add>'
86
- assert_equal expected, RSolr::Message.add(data).to_s
86
+ assert RSolr::Message.add(data).to_s =~ /<field name="name">matt1<\/field>/
87
+ assert RSolr::Message.add(data).to_s =~ /<field name="name">matt2<\/field>/
87
88
  end
88
89
 
89
90
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mwmitchell-rsolr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Mitchell
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-27 00:00:00 -08:00
12
+ date: 2009-03-11 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -39,24 +39,16 @@ files:
39
39
  - lib/core_ext.rb
40
40
  - lib/mash.rb
41
41
  - lib/rsolr.rb
42
- - lib/rsolr/connection/adapter/common_methods.rb
43
- - lib/rsolr/connection/adapter/direct.rb
44
- - lib/rsolr/connection/adapter/http.rb
45
- - lib/rsolr/connection/adapter.rb
46
- - lib/rsolr/connection/base.rb
42
+ - lib/rsolr/adapter/common_methods.rb
43
+ - lib/rsolr/adapter/direct.rb
44
+ - lib/rsolr/adapter/http.rb
45
+ - lib/rsolr/adapter.rb
47
46
  - lib/rsolr/connection.rb
48
47
  - lib/rsolr/http_client/adapter/curb.rb
49
48
  - lib/rsolr/http_client/adapter/net_http.rb
50
49
  - lib/rsolr/http_client/adapter.rb
51
50
  - lib/rsolr/http_client.rb
52
- - lib/rsolr/indexer.rb
53
51
  - lib/rsolr/message.rb
54
- - lib/rsolr/response/base.rb
55
- - lib/rsolr/response/index_info.rb
56
- - lib/rsolr/response/query.rb
57
- - lib/rsolr/response/update.rb
58
- - lib/rsolr/response.rb
59
- - lib/rsolr/query.rb
60
52
  - LICENSE
61
53
  - Rakefile
62
54
  - README.rdoc
@@ -96,12 +88,6 @@ test_files:
96
88
  - test/http_client/net_http_test.rb
97
89
  - test/http_client/test_methods.rb
98
90
  - test/http_client/util_test.rb
99
- - test/indexer.rb
100
91
  - test/message_test.rb
101
- - test/query_helper_test.rb
102
- - test/response/base_test.rb
103
- - test/response/pagination_test.rb
104
- - test/response/query_test.rb
105
92
  - test/rsolr_test
106
- - test/ruby-lang.org.rss.xml
107
93
  - test/test_helpers.rb
@@ -1,7 +0,0 @@
1
- module RSolr::Connection::Adapter
2
-
3
- autoload :Direct, 'rsolr/connection/adapter/direct'
4
- autoload :HTTP, 'rsolr/connection/adapter/http'
5
- autoload :CommonMethods, 'rsolr/connection/adapter/common_methods'
6
-
7
- end
@@ -1,50 +0,0 @@
1
- # This module is for HTTP + DirectSolrConnection (jruby) connections
2
- # It provides common methods.
3
- # The main query, update and index_info methods are here
4
- # The classes that include this module only need to provide a request method like:
5
- # send_request(request_path, params, data)
6
- # where:
7
- # request_path is a string to a handler (/select etc.)
8
- # params is a hash for query string params
9
- # data is optional string of xml
10
- module RSolr::Connection::Adapter::CommonMethods
11
-
12
- # send a request to the "select" handler
13
- # the first argument is the select handler path
14
- # the last argument is a hash of params
15
- def query(*args)
16
- params = args.extract_options!
17
- path = args.first || @opts[:select_path]
18
- self.send_request "/#{path}", params
19
- end
20
-
21
- # sends a request to the admin luke handler to get info on the index
22
- # the first argument is the admin/luke request handler path
23
- # the last argument is a hash of params
24
- def index_info(*args)
25
- params = args.extract_options!
26
- path = args.first || @opts[:luke_path]
27
- params[:numTerms]||=0
28
- self.send_request "/#{path}", params
29
- end
30
-
31
- # sends data to the update handler
32
- # If 2 arguments are passed in:
33
- # - the first should be the POST data string
34
- # - the second can be an optional url params hash
35
- # - the path is defaulted to '/update'
36
- # If 3 arguments are passed in:
37
- # - the first argument should be the url path ('/my-update-handler' etc.)
38
- # - the second should be the POST data string
39
- # - the last/third should be an optional url params hash
40
- # data can be:
41
- # string (valid solr update xml)
42
- # object with respond_to?(:to_xml)
43
- def update(*args)
44
- params = args.extract_options!
45
- data = args.last
46
- path = args.size == 2 ? args.first : @opts[:update_path]
47
- self.send_request "/#{path}", params, data
48
- end
49
-
50
- end