mwmitchell-solr 0.5.3 → 0.5.4

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.
Files changed (38) hide show
  1. data/CHANGES.txt +28 -0
  2. data/README.rdoc +50 -13
  3. data/Rakefile +1 -1
  4. data/examples/direct.rb +6 -4
  5. data/examples/http.rb +7 -2
  6. data/lib/solr/{adapter → connection/adapter}/common_methods.rb +1 -44
  7. data/lib/solr/{adapter → connection/adapter}/direct.rb +28 -13
  8. data/lib/solr/connection/adapter/http.rb +51 -0
  9. data/lib/solr/connection/adapter.rb +7 -0
  10. data/lib/solr/connection/search_ext.rb +28 -24
  11. data/lib/solr/connection.rb +1 -1
  12. data/lib/solr/http_client/adapter/curb.rb +51 -0
  13. data/lib/solr/http_client/adapter/net_http.rb +48 -0
  14. data/lib/solr/http_client/adapter.rb +6 -0
  15. data/lib/solr/http_client.rb +115 -0
  16. data/lib/solr/mapper/rss.rb +2 -0
  17. data/lib/solr/message.rb +5 -1
  18. data/lib/solr/response/base.rb +32 -0
  19. data/lib/solr/response/index_info.rb +22 -0
  20. data/lib/solr/response/query.rb +93 -0
  21. data/lib/solr/response/update.rb +4 -0
  22. data/lib/solr.rb +3 -4
  23. data/test/{direct_test.rb → connection/direct_test.rb} +4 -4
  24. data/test/connection/http_test.rb +19 -0
  25. data/test/{connection_test_methods.rb → connection/test_methods.rb} +14 -4
  26. data/test/http_client/curb_test.rb +19 -0
  27. data/test/http_client/net_http_test.rb +13 -0
  28. data/test/http_client/test_methods.rb +40 -0
  29. data/test/{adapter_common_methods_test.rb → http_client/util_test.rb} +3 -12
  30. data/test/message_test.rb +10 -0
  31. data/test/{ext_pagination_test.rb → pagination_test.rb} +8 -8
  32. data/test/test_helpers.rb +8 -0
  33. metadata +29 -17
  34. data/lib/solr/adapter/http.rb +0 -55
  35. data/lib/solr/adapter.rb +0 -7
  36. data/test/ext_search_test.rb +0 -9
  37. data/test/http_test.rb +0 -15
  38. data/test/indexer_test.rb +0 -14
@@ -1,16 +1,16 @@
1
1
  if defined?(JRUBY_VERSION)
2
2
 
3
- require File.join(File.dirname(__FILE__), 'test_helpers')
3
+ require File.join(File.dirname(__FILE__), '..', 'test_helpers')
4
4
 
5
- require 'connection_test_methods'
5
+ require File.join(File.dirname(__FILE__), 'test_methods')
6
6
 
7
- class DirectTest < Test::Unit::TestCase
7
+ class ConnectionDirectTest < Test::Unit::TestCase
8
8
 
9
9
  include ConnectionTestMethods
10
10
 
11
11
  def setup
12
12
  base = File.expand_path( File.dirname(__FILE__) )
13
- dist = File.join(base, '..', 'apache-solr')
13
+ dist = File.join(base, '..', '..', 'apache-solr')
14
14
  home = File.join(dist, 'example', 'solr')
15
15
  @solr = Solr.connect(:direct, :home_dir=>home, :dist_dir=>dist)
16
16
  @solr.delete_by_query('*:*')
@@ -0,0 +1,19 @@
1
+ unless 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 AdapterHTTPTest < Test::Unit::TestCase
8
+
9
+ include ConnectionTestMethods
10
+
11
+ def setup
12
+ @solr = Solr.connect :http
13
+ @solr.delete_by_query('*:*')
14
+ @solr.commit
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -11,6 +11,16 @@ module ConnectionTestMethods
11
11
  # assert_equal 0, @solr.query(:q=>'*:*').docs.size
12
12
  #end
13
13
 
14
+
15
+ def test_default_options
16
+ target = {
17
+ :select_path => '/select',
18
+ :update_path => '/update',
19
+ :luke_path => '/admin/luke'
20
+ }
21
+ assert_equal target, @solr.adapter.default_options
22
+ end
23
+
14
24
  # setting adapter options in Solr.connect method should set them in the adapter
15
25
  def test_set_adapter_options
16
26
  solr = Solr.connect(:http, :select_path=>'/select2')
@@ -27,14 +37,14 @@ module ConnectionTestMethods
27
37
  # Raw ruby can be returned by using :wt=>'ruby', not :ruby
28
38
  def test_raw_response_formats
29
39
  ruby_response = @solr.query(:q=>'*:*', :wt=>'ruby')
30
- assert ruby_response.is_a?(String)
31
- assert ruby_response=~%r('wt'=>'ruby')
40
+ assert ruby_response[:body].is_a?(String)
41
+ assert ruby_response[:body]=~%r('wt'=>'ruby')
32
42
  # xml?
33
43
  xml_response = @solr.query(:q=>'*:*', :wt=>'xml')
34
- assert xml_response=~%r(<str name="wt">xml</str>)
44
+ assert xml_response[:body]=~%r(<str name="wt">xml</str>)
35
45
  # json?
36
46
  json_response = @solr.query(:q=>'*:*', :wt=>'json')
37
- assert json_response=~%r("wt":"json")
47
+ assert json_response[:body]=~%r("wt":"json")
38
48
  end
39
49
 
40
50
  def test_query_responses
@@ -0,0 +1,19 @@
1
+ # don't run this test in jruby,
2
+ # the curb gem is a c extension based gem, jruby has no support for this
3
+ unless defined?(JRUBY_VERSION)
4
+
5
+ require File.join(File.dirname(__FILE__), '..', 'test_helpers')
6
+
7
+ require File.join(File.dirname(__FILE__), 'test_methods')
8
+
9
+ class CurbTest < Test::Unit::TestCase
10
+
11
+ def setup
12
+ @c ||= Solr::HTTPClient.connect(URL, :curb)
13
+ end
14
+
15
+ include HTTPClientTestMethods
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,13 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helpers')
2
+
3
+ require File.join(File.dirname(__FILE__), 'test_methods')
4
+
5
+ class NetHTTPTest < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @c ||= Solr::HTTPClient.connect(URL, :net_http)
9
+ end
10
+
11
+ include HTTPClientTestMethods
12
+
13
+ end
@@ -0,0 +1,40 @@
1
+ module HTTPClientTestMethods
2
+
3
+ URL = 'http://localhost:8983/solr/'
4
+
5
+ def test_raise_unknown_adapter
6
+ assert_raise Solr::HTTPClient::UnkownAdapterError do
7
+ c = Solr::HTTPClient.connect(URL, :blah)
8
+ end
9
+ end
10
+
11
+ # the responses from the HTTPClient adapter should return the same hash structure
12
+ def test_get_response
13
+ headers = {}
14
+ data = nil
15
+ response = @c.get('select', :q=>'*:*')
16
+ assert_equal data, response[:data]
17
+ assert_equal 200, response[:status_code]
18
+ expected_params = {:q=>'*:*'}
19
+ assert_equal expected_params, response[:params]
20
+ assert_equal 'select', response[:path]
21
+ assert response[:body] =~ /name="responseHeader"/
22
+ assert_equal 'http://localhost:8983/solr/select?q=%2A%3A%2A', response[:url]
23
+ assert_equal headers, response[:headers]
24
+ end
25
+
26
+ def test_post_response
27
+ headers = {"Content-Type" => 'text/xml; charset=utf-8'}
28
+ data = '<add><doc><field name="id">1</field></doc></add>'
29
+ response = @c.post('update', data, {}, headers)
30
+ assert_equal data, response[:data]
31
+ assert_equal 200, response[:status_code]
32
+ expected_params = {}
33
+ assert_equal expected_params, response[:params]
34
+ assert_equal 'update', response[:path]
35
+ assert response[:body] =~ /name="responseHeader"/
36
+ assert_equal 'http://localhost:8983/solr/update', response[:url]
37
+ assert_equal headers, response[:headers]
38
+ end
39
+
40
+ end
@@ -1,24 +1,15 @@
1
- require File.join(File.dirname(__FILE__), 'test_helpers')
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helpers')
2
2
 
3
- class AdapterCommonMethodsTest < Test::Unit::TestCase
3
+ class HTTPUtilTest < Test::Unit::TestCase
4
4
 
5
5
  class DummyClass
6
- include Solr::Adapter::CommonMethods
6
+ include Solr::HTTPClient::Util
7
7
  end
8
8
 
9
9
  def setup
10
10
  @c = DummyClass.new
11
11
  end
12
12
 
13
- def test_default_options
14
- target = {
15
- :select_path => '/select',
16
- :update_path => '/update',
17
- :luke_path => '/admin/luke'
18
- }
19
- assert_equal target, @c.default_options
20
- end
21
-
22
13
  def test_build_url
23
14
  m = @c.method(:build_url)
24
15
  assert_equal '/something', m.call('/something')
data/test/message_test.rb CHANGED
@@ -67,4 +67,14 @@ class MessageTest < Test::Unit::TestCase
67
67
  assert_equal expected, message.to_s
68
68
  end
69
69
 
70
+ # multiValue field support test, thanks to Fouad Mardini!
71
+ def test_add_multi_valued_field
72
+ data = {
73
+ :id => 1,
74
+ :name => ['matt1', 'matt2']
75
+ }
76
+ expected = '<add><doc><field name="id">1</field><field name="name">matt1</field><field name="name">matt2</field></doc></add>'
77
+ assert_equal expected, Solr::Message.add(data).to_s
78
+ end
79
+
70
80
  end
@@ -1,6 +1,6 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helpers')
2
2
 
3
- class ExtPaginationTest < Test::Unit::TestCase
3
+ class PaginationTest < Test::Unit::TestCase
4
4
 
5
5
  def create_response(params={})
6
6
  response = Solr::Response::Query::Base.new(mock_query_response)
@@ -10,19 +10,19 @@ class ExtPaginationTest < Test::Unit::TestCase
10
10
 
11
11
  # test the Solr::Connection pagination methods
12
12
  def test_connection_calculate_start
13
- dp = Solr::Connection::Base.new(nil)
14
- assert_equal 15, dp.send(:calculate_start, 2, 15)
15
- assert_equal 450, dp.send(:calculate_start, 10, 50)
16
- assert_equal 0, dp.send(:calculate_start, 0, 50)
13
+ dummy_connection = Solr::Connection::Base.new(nil)
14
+ assert_equal 15, dummy_connection.send(:calculate_start, 2, 15)
15
+ assert_equal 450, dummy_connection.send(:calculate_start, 10, 50)
16
+ assert_equal 0, dummy_connection.send(:calculate_start, 0, 50)
17
17
  end
18
18
 
19
19
  def test_connection_modify_params_for_pagination
20
- dp = Solr::Connection::Base.new(nil)
21
- p = dp.send(:modify_params_for_pagination, {:page=>1})
20
+ dummy_connection = Solr::Connection::Base.new(nil)
21
+ p = dummy_connection.send(:modify_params_for_pagination, {:page=>1})
22
22
  assert_equal 0, p[:start]
23
23
  assert_equal 10, p[:rows]
24
24
  #
25
- p = dp.send(:modify_params_for_pagination, {:page=>10, :per_page=>100})
25
+ p = dummy_connection.send(:modify_params_for_pagination, {:page=>10, :per_page=>100})
26
26
  assert_equal 900, p[:start]
27
27
  assert_equal 100, p[:rows]
28
28
  end
data/test/test_helpers.rb CHANGED
@@ -2,6 +2,14 @@ $: << File.dirname(__FILE__)
2
2
  require File.join(File.dirname(__FILE__), '..', 'lib', 'solr')
3
3
  require 'test/unit'
4
4
 
5
+ class SolrBaseTest < Test::Unit::TestCase
6
+
7
+ def default_test
8
+
9
+ end
10
+
11
+ end
12
+
5
13
  #begin
6
14
  # require 'rubygems'
7
15
  # require 'redgreen'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mwmitchell-solr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
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: 2008-12-16 00:00:00 -08:00
12
+ date: 2008-12-29 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -32,24 +32,33 @@ extra_rdoc_files: []
32
32
  files:
33
33
  - examples/http.rb
34
34
  - examples/direct.rb
35
- - lib/solr.rb
36
35
  - lib/core_ext.rb
37
- - lib/solr/adapter.rb
38
- - lib/solr/adapter/common_methods.rb
39
- - lib/solr/adapter/direct.rb
40
- - lib/solr/adapter/http.rb
41
- - lib/solr/connection.rb
36
+ - lib/solr.rb
37
+ - lib/solr/connection/adapter/common_methods.rb
38
+ - lib/solr/connection/adapter/direct.rb
39
+ - lib/solr/connection/adapter/http.rb
40
+ - lib/solr/connection/adapter.rb
42
41
  - lib/solr/connection/base.rb
43
42
  - lib/solr/connection/search_ext.rb
43
+ - lib/solr/connection.rb
44
+ - lib/solr/http_client/adapter/curb.rb
45
+ - lib/solr/http_client/adapter/net_http.rb
46
+ - lib/solr/http_client/adapter.rb
47
+ - lib/solr/http_client.rb
44
48
  - lib/solr/indexer.rb
45
- - lib/solr/mapper.rb
46
49
  - lib/solr/mapper/rss.rb
50
+ - lib/solr/mapper.rb
47
51
  - lib/solr/message.rb
52
+ - lib/solr/response/base.rb
53
+ - lib/solr/response/index_info.rb
54
+ - lib/solr/response/query.rb
55
+ - lib/solr/response/update.rb
48
56
  - lib/solr/response.rb
49
57
  - LICENSE
50
58
  - Rakefile
51
59
  - README.rdoc
52
60
  - solr-ruby.gemspec
61
+ - CHANGES.txt
53
62
  has_rdoc: true
54
63
  homepage: http://github.com/mwmitchell/solr
55
64
  post_install_message:
@@ -77,15 +86,18 @@ signing_key:
77
86
  specification_version: 2
78
87
  summary: Ruby client for Apache Solr
79
88
  test_files:
80
- - test/adapter_common_methods_test.rb
81
- - test/connection_test_methods.rb
82
- - test/direct_test.rb
83
- - test/ext_pagination_test.rb
84
- - test/ext_params_test.rb
85
- - test/ext_search_test.rb
86
- - test/http_test.rb
87
- - test/indexer_test.rb
89
+ - test/connection/direct_test.rb
90
+ - test/connection/http_test.rb
91
+ - test/connection/test_methods.rb
92
+ - test/core_ext_test
93
+ - test/http_client/curb_test.rb
94
+ - test/http_client/net_http_test.rb
95
+ - test/http_client/test_methods.rb
96
+ - test/http_client/util_test.rb
97
+ - test/indexer.rb
88
98
  - test/mapper_test.rb
89
99
  - test/message_test.rb
100
+ - test/pagination_test.rb
90
101
  - test/ruby-lang.org.rss.xml
102
+ - test/solr_test
91
103
  - test/test_helpers.rb
@@ -1,55 +0,0 @@
1
- require 'net/http'
2
-
3
- #
4
- # Connection for standard HTTP Solr server
5
- #
6
- class Solr::Adapter::HTTP
7
-
8
- include Solr::Adapter::CommonMethods
9
-
10
- attr_accessor :opts, :connection, :url
11
-
12
- # opts can have:
13
- # :url => 'http://localhost:8080/solr'
14
- # :select_path => '/the/url/path/to/the/select/handler'
15
- # :update_path => '/the/url/path/to/the/update/handler'
16
- # :luke_path => '/admin/luke'
17
- #
18
- # If a block is given, the @connection (Net::HTTP) instance is yielded
19
- def initialize(opts={}, &block)
20
- opts[:url]||='http://127.0.0.1:8983/solr'
21
- @url = URI.parse(opts[:url])
22
- @connection = Net::HTTP.new(@url.host, @url.port)
23
- yield @connection if block_given?
24
- @opts = default_options.merge(opts)
25
- end
26
-
27
- # send a request to the connection
28
- # request '/update', :wt=>:xml, '</commit>'
29
- def send_request(request_url_path, params={}, data=nil)
30
- data = data.to_xml if data.respond_to?(:to_xml)
31
- full_path = build_url(@url.path + request_url_path, params)
32
- if data
33
- response = @connection.post(full_path, data, post_headers)
34
- else
35
- response = @connection.get(full_path)
36
- end
37
- unless response.code=='200'
38
- raise Solr::RequestError.new(parse_solr_html_error(response.body))
39
- end
40
- response.body
41
- end
42
-
43
- protected
44
-
45
- # The standard post headers
46
- def post_headers
47
- {"Content-Type" => 'text/xml', 'charset'=>'utf-8'}
48
- end
49
-
50
- # extracts the message from the solr error response
51
- def parse_solr_html_error(html)
52
- html.scan(/<pre>(.*)<\/pre>/mi).first.first.gsub(/&lt;/, '<').gsub(/&gt;/, '>') rescue html
53
- end
54
-
55
- end
data/lib/solr/adapter.rb DELETED
@@ -1,7 +0,0 @@
1
- module Solr::Adapter
2
-
3
- autoload :Direct, 'solr/adapter/direct'
4
- autoload :HTTP, 'solr/adapter/http'
5
- autoload :CommonMethods, 'solr/adapter/common_methods'
6
-
7
- end
@@ -1,9 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'test_helpers')
2
-
3
- class ExtSearchTest < Test::Unit::TestCase
4
-
5
- def test_mapping_methods
6
-
7
- end
8
-
9
- end
data/test/http_test.rb DELETED
@@ -1,15 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'test_helpers')
2
-
3
- require 'connection_test_methods'
4
-
5
- class HTTPTest < Test::Unit::TestCase
6
-
7
- include ConnectionTestMethods
8
-
9
- def setup
10
- @solr = Solr.connect :http
11
- @solr.delete_by_query('*:*')
12
- @solr.commit
13
- end
14
-
15
- end
data/test/indexer_test.rb DELETED
@@ -1,14 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'test_helpers')
2
-
3
- class IndexerTest < Test::Unit::TestCase
4
-
5
- def test_something
6
- data = nil
7
- mapping = {
8
-
9
- }
10
- i = Solr::Indexer.new(Solr.connect(:http), mapping)
11
- i.index([])
12
- end
13
-
14
- end