mwmitchell-rsolr 0.9.5 → 0.9.6

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.
@@ -1,3 +1,8 @@
1
+ 0.9.6 - September 9, 2009
2
+ Added ability to create direct connections from existing Java::OrgApacheSolrCore::SolrCore
3
+ Added ability to send queries using POST
4
+ - solr.request '/select', :q=>'*:*', :method=>:post
5
+
1
6
  0.9.5 - September 4, 2009
2
7
  Removed Array #extract_options!
3
8
  Removed the Connection #send_request method (now #request)
@@ -18,17 +18,16 @@ module RSolr::Connection
18
18
  end
19
19
 
20
20
  # Send a request to a request handler using the method name.
21
- # This does not handle data/POSTs, only GET requests.
22
- def method_missing(method_name, params, &blk)
23
- request("/#{method_name}", map_params(params))
21
+ def method_missing(method_name, *args, &blk)
22
+ request("/#{method_name}", *args, &blk)
24
23
  end
25
-
24
+
26
25
  # sends data to the update handler
27
26
  # data can be a string of xml, or an object that returns xml from its #to_xml method
28
27
  def update(data, params={})
29
- request('/update', map_params(params), data)
28
+ request '/update', params, data
30
29
  end
31
-
30
+
32
31
  # send request solr
33
32
  # params is hash with valid solr request params (:q, :fl, :qf etc..)
34
33
  # if params[:wt] is not set, the default is :ruby
@@ -37,11 +36,11 @@ module RSolr::Connection
37
36
  # NOTE: to get raw ruby, use :wt=>'ruby' <- a string, not a symbol like :ruby
38
37
  #
39
38
  #
40
- def request(path, params={}, data=nil)
41
- response = @adapter.request(path, map_params(params), data)
39
+ def request(path, params={}, *extra)
40
+ response = @adapter.request(path, map_params(params), *extra)
42
41
  adapt_response(response)
43
42
  end
44
-
43
+
45
44
  #
46
45
  # single record:
47
46
  # solr.update(:id=>1, :name=>'one')
@@ -23,7 +23,9 @@ class RSolr::Connection::Adapter::Direct
23
23
  # :select_path => 'the/select/handler'
24
24
  # :update_path => 'the/update/handler'
25
25
  def initialize(opts, &block)
26
- if defined?(Java::OrgApacheSolrServlet::DirectSolrConnection) and opts.is_a?(Java::OrgApacheSolrServlet::DirectSolrConnection)
26
+ if defined?(Java::OrgApacheSolrCore::SolrCore) and opts.is_a?(Java::OrgApacheSolrCore::SolrCore)
27
+ @connection = org.apache.solr.servlet.DirectSolrConnection.new(opts)
28
+ elsif defined?(Java::OrgApacheSolrServlet::DirectSolrConnection) and opts.is_a?(Java::OrgApacheSolrServlet::DirectSolrConnection)
27
29
  @connection = opts
28
30
  else
29
31
  opts[:data_dir] ||= File.join(opts[:home_dir].to_s, 'data')
@@ -54,7 +56,7 @@ class RSolr::Connection::Adapter::Direct
54
56
  # send a request to the connection
55
57
  # request '/select', :q=>'something'
56
58
  # request '/update', :wt=>:xml, '</commit>'
57
- def request(path, params={}, data=nil)
59
+ def request(path, params={}, data=nil, opts={})
58
60
  data = data.to_xml if data.respond_to?(:to_xml)
59
61
  url = build_url(path, params)
60
62
  begin
@@ -3,6 +3,8 @@
3
3
  #
4
4
  class RSolr::Connection::Adapter::HTTP
5
5
 
6
+ include RSolr::HTTPClient::Util
7
+
6
8
  attr_reader :opts
7
9
 
8
10
  # opts can have:
@@ -18,22 +20,23 @@ class RSolr::Connection::Adapter::HTTP
18
20
 
19
21
  # send a request to the connection
20
22
  # request '/update', :wt=>:xml, '</commit>'
21
- def request(path, params={}, data=nil)
22
- data = data.to_xml if data.respond_to?(:to_xml)
23
- if data
24
- http_context = connection.post(path, data, params, post_headers)
23
+ def request(path, params={}, *extra)
24
+ opts = extra[-1].kind_of?(Hash) ? extra.pop : {}
25
+ data = extra[0]
26
+ # force a POST, use the query string as the POST body
27
+ if opts[:method] == :post and data.to_s.empty?
28
+ http_context = connection.post(path, hash_to_query(params), {}, {'Content-Type' => 'application/x-www-form-urlencoded'})
25
29
  else
26
- http_context = connection.get(path, params)
30
+ if data
31
+ # standard POST, using "data" as the POST body
32
+ http_context = connection.post(path, data, params, {"Content-Type" => 'text/xml; charset=utf-8'})
33
+ else
34
+ # standard GET
35
+ http_context = connection.get(path, params)
36
+ end
27
37
  end
28
38
  raise RSolr::RequestError.new(http_context[:body]) unless http_context[:status_code] == 200
29
39
  http_context
30
40
  end
31
41
 
32
- protected
33
-
34
- # The standard POST headers
35
- def post_headers
36
- {"Content-Type" => 'text/xml; charset=utf-8'}
37
- end
38
-
39
42
  end
@@ -1,8 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
-
3
2
  s.name = "rsolr"
4
- s.version = "0.9.5"
5
- s.date = "2009-09-05"
3
+ s.version = "0.9.6"
4
+ s.date = "2009-09-12"
6
5
  s.summary = "A Ruby client for Apache Solr"
7
6
  s.email = "goodieboy@gmail.com"
8
7
  s.homepage = "http://github.com/mwmitchell/rsolr"
@@ -6,13 +6,24 @@ unless defined?(JRUBY_VERSION)
6
6
  class AdapterHTTPTest < RSolrBaseTest
7
7
 
8
8
  include ConnectionTestMethods
9
-
9
+
10
10
  def setup
11
11
  @solr = RSolr.connect(:http)
12
12
  @solr.delete_by_query('*:*')
13
13
  @solr.commit
14
14
  end
15
-
15
+
16
+ # http://www.w3.org/TR/html4/interact/forms.html#submit-format
17
+
18
+ # due to the way some servers implement their query string parsing,
19
+ # POST is sometimes needed for large query strings.
20
+ # This test simply shows that a large q value will not blow up solr.
21
+ def test_post_for_select
22
+ big_honkin_q = (['ipod']*1000).join(' OR ')
23
+ response = @solr.adapter.request '/select', {:q=>big_honkin_q}, :method=>:post
24
+ assert response
25
+ end
26
+
16
27
  end
17
28
 
18
29
  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.9.5
4
+ version: 0.9.6
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-09-05 00:00:00 -07:00
12
+ date: 2009-09-12 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -53,7 +53,6 @@ files:
53
53
  - CHANGES.txt
54
54
  has_rdoc: true
55
55
  homepage: http://github.com/mwmitchell/rsolr
56
- licenses:
57
56
  post_install_message:
58
57
  rdoc_options: []
59
58
 
@@ -74,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
73
  requirements: []
75
74
 
76
75
  rubyforge_project:
77
- rubygems_version: 1.3.5
76
+ rubygems_version: 1.2.0
78
77
  signing_key:
79
78
  specification_version: 2
80
79
  summary: A Ruby client for Apache Solr