rsolr 0.9.6 → 0.9.7.1

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.
@@ -12,7 +12,7 @@ if defined?(JRUBY_VERSION)
12
12
 
13
13
  def setup
14
14
  base = File.expand_path( File.dirname(__FILE__) )
15
- @dist = File.join(base, '..', '..', 'apache-solr')
15
+ @dist = File.join(base, '..', '..', 'solr')
16
16
  @home = File.join(dist, 'example', 'solr')
17
17
  @solr = RSolr.connect(:direct, :home_dir=>@home, :dist_dir=>@dist)
18
18
  @solr.delete_by_query('*:*')
@@ -26,7 +26,7 @@ if defined?(JRUBY_VERSION)
26
26
  def test_new_connection_with_existing_core
27
27
  Dir["#{@dist}/dist/*.jar"].each { |p| require p }
28
28
  dc = org.apache.solr.servlet.DirectSolrConnection.new(@home, "#{@home}/data", nil)
29
- adapter = RSolr::Connection::Adapter::Direct.new dc
29
+ adapter = RSolr::Connection::Direct.new dc
30
30
  s = RSolr::Connection::Base.new(adapter)
31
31
  assert_equal Hash, s.request('/admin/ping').class
32
32
  adapter.close
@@ -3,12 +3,12 @@ unless defined?(JRUBY_VERSION)
3
3
  require 'helper'
4
4
  require 'connection/test_methods'
5
5
 
6
- class AdapterHTTPTest < RSolrBaseTest
6
+ class NetHttpTest < RSolrBaseTest
7
7
 
8
8
  include ConnectionTestMethods
9
9
 
10
10
  def setup
11
- @solr = RSolr.connect(:http)
11
+ @solr = RSolr.connect
12
12
  @solr.delete_by_query('*:*')
13
13
  @solr.commit
14
14
  end
@@ -3,7 +3,7 @@ require 'helper'
3
3
  class HTTPUtilTest < RSolrBaseTest
4
4
 
5
5
  class DummyClass
6
- include RSolr::HTTPClient::Util
6
+ include RSolr::Connection::Utils
7
7
  end
8
8
 
9
9
  def setup
data/test/message_test.rb CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  require 'helper'
3
3
 
4
- module MessageTestMethods
4
+ class BuilderMessageTest < RSolrBaseTest
5
5
 
6
6
  def builder
7
7
  @builder ||= RSolr::Message::Builder.new
@@ -90,7 +90,7 @@ module MessageTestMethods
90
90
 
91
91
  message = self.builder.add(data)
92
92
  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>'
93
-
93
+
94
94
  assert message.to_s=~/<field name="name">matt<\/field>/
95
95
  assert message.to_s=~/<field name="name">sam<\/field>/
96
96
  end
@@ -137,31 +137,4 @@ module MessageTestMethods
137
137
  assert result.to_s =~ /<field name="name">matt2<\/field>/
138
138
  end
139
139
 
140
- end
141
-
142
- #####
143
-
144
- unless defined?(JRUBY_VERSION)
145
- class LibxmlMessageTest < RSolrBaseTest
146
-
147
- include MessageTestMethods
148
-
149
- def setup
150
- self.builder.adapter = RSolr::Message::Adapter::Libxml.new
151
- end
152
-
153
- end
154
- end
155
-
156
-
157
- #####
158
-
159
- class BuilderMessageTest < RSolrBaseTest
160
-
161
- include MessageTestMethods
162
-
163
- def setup
164
- self.builder.adapter = RSolr::Message::Adapter::Builder.new
165
- end
166
-
167
140
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsolr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.6
4
+ version: 0.9.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Mitchell
@@ -9,19 +9,10 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-12 00:00:00 -04:00
12
+ date: 2009-11-05 00:00:00 -05:00
13
13
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: builder
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 2.1.2
24
- version:
14
+ dependencies: []
15
+
25
16
  description: RSolr is a Ruby gem for working with Apache Solr!
26
17
  email: goodieboy@gmail.com
27
18
  executables: []
@@ -34,22 +25,17 @@ extra_rdoc_files:
34
25
  - README.rdoc
35
26
  - CHANGES.txt
36
27
  files:
37
- - examples/http.rb
38
28
  - examples/direct.rb
39
- - lib/rsolr.rb
40
- - lib/rsolr/connection/adapter/direct.rb
41
- - lib/rsolr/connection/adapter/http.rb
29
+ - examples/http.rb
30
+ - lib/rsolr/connection/direct.rb
31
+ - lib/rsolr/connection/net_http.rb
42
32
  - lib/rsolr/connection.rb
43
- - lib/rsolr/http_client/adapter/curb.rb
44
- - lib/rsolr/http_client/adapter/net_http.rb
45
- - lib/rsolr/http_client.rb
46
- - lib/rsolr/message/adapter/builder.rb
47
- - lib/rsolr/message/adapter/libxml.rb
48
33
  - lib/rsolr/message.rb
34
+ - lib/rsolr.rb
35
+ - lib/xout.rb
49
36
  - LICENSE
50
37
  - Rakefile
51
38
  - README.rdoc
52
- - rsolr.gemspec
53
39
  - CHANGES.txt
54
40
  has_rdoc: true
55
41
  homepage: http://github.com/mwmitchell/rsolr
@@ -75,18 +61,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
61
  requirements: []
76
62
 
77
63
  rubyforge_project:
78
- rubygems_version: 1.3.4
64
+ rubygems_version: 1.3.5
79
65
  signing_key:
80
66
  specification_version: 3
81
67
  summary: A Ruby client for Apache Solr
82
68
  test_files:
83
69
  - test/connection/direct_test.rb
84
- - test/connection/http_test.rb
70
+ - test/connection/net_http_test.rb
85
71
  - test/connection/test_methods.rb
72
+ - test/connection/utils_test.rb
86
73
  - test/helper.rb
87
- - test/http_client/curb_test.rb
88
- - test/http_client/net_http_test.rb
89
- - test/http_client/test_methods.rb
90
- - test/http_client/util_test.rb
91
74
  - test/message_test.rb
92
75
  - test/rsolr_test.rb
@@ -1,42 +0,0 @@
1
- #
2
- # Connection for standard HTTP Solr server
3
- #
4
- class RSolr::Connection::Adapter::HTTP
5
-
6
- include RSolr::HTTPClient::Util
7
-
8
- attr_reader :opts
9
-
10
- # opts can have:
11
- # :url => 'http://localhost:8080/solr'
12
- def initialize(opts={}, &block)
13
- opts[:url] ||= 'http://127.0.0.1:8983/solr'
14
- @opts = opts
15
- end
16
-
17
- def connection
18
- @connection ||= RSolr::HTTPClient.connect(@opts)
19
- end
20
-
21
- # send a request to the connection
22
- # request '/update', :wt=>:xml, '</commit>'
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'})
29
- else
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
37
- end
38
- raise RSolr::RequestError.new(http_context[:body]) unless http_context[:status_code] == 200
39
- http_context
40
- end
41
-
42
- end
@@ -1,51 +0,0 @@
1
- require 'rubygems'
2
- require 'curb'
3
-
4
- class RSolr::HTTPClient::Adapter::Curb
5
-
6
- include RSolr::HTTPClient::Util
7
-
8
- attr :uri
9
- attr :connection
10
-
11
- def initialize(opts={})
12
- @uri = URI.parse(opts[:url])
13
- @connection = ::Curl::Easy.new
14
- end
15
-
16
- def get(path, params={})
17
- @connection.url = _build_url(path, params)
18
- @connection.multipart_form_post = false
19
- @connection.perform
20
- create_http_context(path, params)
21
- end
22
-
23
- def post(path, data, params={}, headers={})
24
- @connection.url = _build_url(path, params)
25
- @connection.headers = headers
26
- @connection.http_post(data)
27
- create_http_context(path, params, data, headers)
28
- end
29
-
30
- protected
31
-
32
- def create_http_context(path, params, data=nil, headers={})
33
- {
34
- :status_code=>@connection.response_code.to_i,
35
- :url=>@connection.url,
36
- :body=>@connection.body_str,
37
- :path=>path,
38
- :params=>params,
39
- :data=>data,
40
- :headers=>headers
41
- }
42
- end
43
-
44
- def _build_url(path, params={})
45
- url = @uri.scheme + '://' + @uri.host
46
- url += ':' + @uri.port.to_s if @uri.port
47
- url += @uri.path + path
48
- build_url(url, params, @uri.query) # build_url is coming from RSolr::HTTPClient::Util
49
- end
50
-
51
- end
@@ -1,48 +0,0 @@
1
- require 'net/http'
2
-
3
- class RSolr::HTTPClient::Adapter::NetHTTP
4
-
5
- include RSolr::HTTPClient::Util
6
-
7
- attr :uri
8
- attr :connection
9
-
10
- def initialize(opts={})
11
- @uri = URI.parse(opts[:url])
12
- @connection = Net::HTTP.new(@uri.host, @uri.port)
13
- end
14
-
15
- def get(path, params={})
16
- url = _build_url(path, params)
17
- net_http_response = @connection.get(url)
18
- create_http_context(net_http_response, url, path, params)
19
- end
20
-
21
- def post(path, data, params={}, headers={})
22
- url = _build_url(path, params)
23
- net_http_response = @connection.post(url, data, headers)
24
- create_http_context(net_http_response, url, path, params, data, headers)
25
- end
26
-
27
- protected
28
-
29
- def create_http_context(net_http_response, url, path, params, data=nil, headers={})
30
- full_url = "#{@uri.scheme}://#{@uri.host}"
31
- full_url += @uri.port ? ":#{@uri.port}" : ''
32
- full_url += url
33
- {
34
- :status_code=>net_http_response.code.to_i,
35
- :url=>full_url,
36
- :body=>net_http_response.body,
37
- :path=>path,
38
- :params=>params,
39
- :data=>data,
40
- :headers=>headers
41
- }
42
- end
43
-
44
- def _build_url(path, params={})
45
- build_url(@uri.path + path, params, @uri.query) # build_url is coming from RSolr::HTTPClient::Util
46
- end
47
-
48
- end
@@ -1,149 +0,0 @@
1
- # A simple wrapper for different http client implementations.
2
- # Supports #get and #post
3
- # This was motivated by: http://apocryph.org/2008/11/09/more_indepth_analysis_ruby_http_client_performance/
4
-
5
- # Each adapters' response should be a hash with the following keys:
6
- # :status_code
7
- # :url
8
- # :body
9
- # :path
10
- # :params
11
- # :data
12
- # :headers
13
-
14
- # Example:
15
- # hclient = RSolr::HTTPClient.connect('http://www.google.com')
16
- # # SAME AS
17
- # hclient = RSolr::HTTPClient.connect(:net_http, 'http://www.google.com')
18
- # hclient = RSolr::HTTPClient.connect(:curb, 'http://www.google.com')
19
- # response = hclient.get('/search', :hl=>:en, :q=>:ruby, :btnG=>:Search)
20
- # puts response[:status_code]
21
- # puts response[:body]
22
-
23
- require 'uri'
24
-
25
- module RSolr::HTTPClient
26
-
27
- module Adapter
28
- autoload :Curb, 'rsolr/http_client/adapter/curb'
29
- autoload :NetHTTP, 'rsolr/http_client/adapter/net_http'
30
- end
31
-
32
- class UnkownAdapterError < RuntimeError
33
- end
34
-
35
- class Base
36
-
37
- attr_reader :adapter
38
-
39
- # requires an instace of RSolr::HTTPClient::*
40
- def initialize(adapter)
41
- @adapter = adapter
42
- end
43
-
44
- # sends a GET reqest to the "path" variable
45
- # an optional hash of "params" can be used,
46
- # which is later transformed into a GET query string
47
- def get(path, params={})
48
- begin
49
- http_context = @adapter.get(path, params)
50
- rescue
51
- raise RSolr::RequestError.new($!)
52
- end
53
- http_context
54
- end
55
-
56
- # sends a POST request to the "path" variable
57
- # "data" is required, and must be a string
58
- # "params" is an optional hash for query string params...
59
- # "headers" is a hash for setting request header values.
60
- def post(path, data, params={}, headers={})
61
- begin
62
- http_context = @adapter.post(path, data, params, headers)
63
- rescue
64
- raise RSolr::RequestError.new($!)
65
- end
66
- http_context
67
- end
68
-
69
- end
70
-
71
- # Factory for creating connections.
72
- # Can specify the connection type by
73
- # using :net_http or :curb for the first argument.
74
- # The ending arguments are always used for the connection adapter instance.
75
- #
76
- # Examples:
77
- # # default net_http connection
78
- # RSolr::HTTPClient.connect :url=>''
79
- # # SAME AS
80
- # RSolr::HTTPClient.connect :net_http, :url=>''
81
- # # curb connection
82
- # RSolr.connect :curb, :url=>''
83
- def self.connect(*args)
84
- type = args.first.is_a?(Symbol) ? args.shift : :net_http
85
- opts = args
86
- klass = case type
87
- when :net_http,nil
88
- 'NetHTTP'
89
- when :curb
90
- 'Curb'
91
- else
92
- raise UnkownAdapterError.new("Invalid adapter type: #{type} - use :curb or :net_http or blank for :net_http/default")
93
- end
94
- begin
95
- Base.new Adapter.const_get(klass).new(*args)
96
- end
97
- end
98
-
99
- module Util
100
-
101
- # Performs URI escaping so that you can construct proper
102
- # query strings faster. Use this rather than the cgi.rb
103
- # version since it's faster. (Stolen from Rack).
104
- def escape(s)
105
- s.to_s.gsub(/([^ a-zA-Z0-9_.-]+)/n) {
106
- '%'+$1.unpack('H2'*$1.size).join('%').upcase
107
- }.tr(' ', '+')
108
- end
109
-
110
- # creates and returns a url as a string
111
- # "url" is the base url
112
- # "params" is an optional hash of GET style query params
113
- # "string_query" is an extra query string that will be appended to the
114
- # result of "url" and "params".
115
- def build_url(url='', params={}, string_query='')
116
- queries = [string_query, hash_to_query(params)]
117
- queries.delete_if{|i| i.to_s.empty?}
118
- url += "?#{queries.join('&')}" unless queries.empty?
119
- url
120
- end
121
-
122
- # converts a key value pair to an escaped string:
123
- # Example:
124
- # build_param(:id, 1) == "id=1"
125
- def build_param(k,v)
126
- "#{escape(k)}=#{escape(v)}"
127
- end
128
-
129
- #
130
- # converts hash into URL query string, keys get an alpha sort
131
- # if a value is an array, the array values get mapped to the same key:
132
- # hash_to_query(:q=>'blah', :fq=>['blah', 'blah'], :facet=>{:field=>['location_facet', 'format_facet']})
133
- # returns:
134
- # ?q=blah&fq=blah&fq=blah&facet.field=location_facet&facet.field=format.facet
135
- #
136
- # if a value is empty/nil etc., the key is not added
137
- def hash_to_query(params)
138
- params.map { |k, v|
139
- if v.class == Array
140
- hash_to_query(v.map { |x| [k, x] })
141
- else
142
- build_param k, v
143
- end
144
- }.join("&")
145
- end
146
-
147
- end
148
-
149
- end
@@ -1,85 +0,0 @@
1
- require 'builder'
2
-
3
- class RSolr::Message::Adapter::Builder
4
-
5
- # shortcut method -> xml = RSolr::Message.xml
6
- def xml
7
- ::Builder::XmlMarkup.new
8
- end
9
-
10
- # generates "add" xml for updating solr
11
- # "data" can be a hash or an array of hashes.
12
- # - each hash should be a simple key=>value pair representing a solr doc.
13
- # If a value is an array, multiple fields will be created.
14
- #
15
- # "add_attrs" can be a hash for setting the add xml element attributes.
16
- #
17
- # This method can also accept a block.
18
- # The value yielded to the block is a Message::Document; for each solr doc in "data".
19
- # You can set xml element attributes for each "doc" element or individual "field" elements.
20
- #
21
- # For example:
22
- #
23
- # solr.add({:id=>1, :nickname=>'Tim'}, {:boost=>5.0, :commitWithin=>1.0}) do |doc_msg|
24
- # doc_msg.attrs[:boost] = 10.00 # boost the document
25
- # nickname = doc_msg.field_by_name(:nickname)
26
- # nickname.attrs[:boost] = 20 if nickname.value=='Tim' # boost a field
27
- # end
28
- #
29
- # would result in an add element having the attributes boost="10.0"
30
- # and a commitWithin="1.0".
31
- # Each doc element would have a boost="10.0".
32
- # The "nickname" field would have a boost="20.0"
33
- # if the doc had a "nickname" field with the value of "Tim".
34
- #
35
- def add(documents, add_attrs={})
36
- xml.add(add_attrs) do |add_node|
37
- documents.each do |doc|
38
- # create doc, passing in fields
39
- add_node.doc(doc.attrs) do |doc_node|
40
- doc.fields.each do |field_obj|
41
- doc_node.field(field_obj.value, field_obj.attrs)
42
- end
43
- end
44
- end
45
- end
46
- end
47
-
48
- # generates a <commit/> message
49
- def commit(opts={})
50
- xml.commit(opts)
51
- end
52
-
53
- # generates a <optimize/> message
54
- def optimize(opts={})
55
- xml.optimize(opts)
56
- end
57
-
58
- # generates a <rollback/> message
59
- def rollback
60
- xml.rollback
61
- end
62
-
63
- # generates a <delete><id>ID</id></delete> message
64
- # "ids" can be a single value or array of values
65
- def delete_by_id(ids)
66
- ids = [ids] unless ids.is_a?(Array)
67
- xml.delete do |xml|
68
- ids.each do |id|
69
- xml.id(id)
70
- end
71
- end
72
- end
73
-
74
- # generates a <delete><query>ID</query></delete> message
75
- # "queries" can be a single value or an array of values
76
- def delete_by_query(queries)
77
- queries = [queries] unless queries.is_a?(Array)
78
- xml.delete do |xml|
79
- queries.each do |query|
80
- xml.query(query)
81
- end
82
- end
83
- end
84
-
85
- end
@@ -1,59 +0,0 @@
1
- require 'libxml'
2
-
3
- class RSolr::Message::Adapter::Libxml
4
-
5
- def add(documents, attributes = {})
6
- add_node = new_node('add', attributes)
7
- for document in documents
8
- add_node << doc_node = new_node('doc', document.attrs)
9
- for field in document.fields
10
- doc_node << field_node = new_node('field', field.attrs)
11
- field_node << field.value
12
- end
13
- end
14
- add_node.to_s(:indent => false)
15
- end
16
-
17
- def delete_by_id(ids)
18
- delete = new_node('delete')
19
- for id in Array(ids)
20
- id_node = new_node('id')
21
- id_node << id
22
- delete << id_node
23
- end
24
- delete.to_s(:indent => false)
25
- end
26
-
27
- def delete_by_query(queries)
28
- delete = new_node('delete')
29
- for query in Array(queries)
30
- query_node = new_node('query')
31
- query_node << query
32
- delete << query_node
33
- end
34
- delete.to_s(:indent => false)
35
- end
36
-
37
- def optimize(opts)
38
- new_node('optimize', opts).to_s
39
- end
40
-
41
- def rollback
42
- new_node('rollback').to_s
43
- end
44
-
45
- def commit(opts = {})
46
- new_node('commit', opts).to_s
47
- end
48
-
49
- private
50
-
51
- def new_node(name, opts = {})
52
- node = LibXML::XML::Node.new(name)
53
- opts.each_pair do |attr, value|
54
- node[attr.to_s] = value.to_s
55
- end
56
- node
57
- end
58
-
59
- end
data/rsolr.gemspec DELETED
@@ -1,46 +0,0 @@
1
- Gem::Specification.new do |s|
2
- s.name = "rsolr"
3
- s.version = "0.9.6"
4
- s.date = "2009-09-12"
5
- s.summary = "A Ruby client for Apache Solr"
6
- s.email = "goodieboy@gmail.com"
7
- s.homepage = "http://github.com/mwmitchell/rsolr"
8
- s.description = "RSolr is a Ruby gem for working with Apache Solr!"
9
- s.has_rdoc = true
10
- s.authors = ["Matt Mitchell"]
11
-
12
- s.files = [
13
- "examples/http.rb",
14
- "examples/direct.rb",
15
- "lib/rsolr.rb",
16
- "lib/rsolr/connection/adapter/direct.rb",
17
- "lib/rsolr/connection/adapter/http.rb",
18
- "lib/rsolr/connection.rb",
19
- "lib/rsolr/http_client/adapter/curb.rb",
20
- "lib/rsolr/http_client/adapter/net_http.rb",
21
- "lib/rsolr/http_client.rb",
22
- "lib/rsolr/message/adapter/builder.rb",
23
- "lib/rsolr/message/adapter/libxml.rb",
24
- "lib/rsolr/message.rb",
25
- "LICENSE",
26
- "Rakefile",
27
- "README.rdoc",
28
- "rsolr.gemspec",
29
- "CHANGES.txt"
30
- ]
31
- s.test_files = [
32
- "test/connection/direct_test.rb",
33
- "test/connection/http_test.rb",
34
- "test/connection/test_methods.rb",
35
- "test/helper.rb",
36
- "test/http_client/curb_test.rb",
37
- "test/http_client/net_http_test.rb",
38
- "test/http_client/test_methods.rb",
39
- "test/http_client/util_test.rb",
40
- "test/message_test.rb",
41
- "test/rsolr_test.rb"
42
- ]
43
- #s.rdoc_options = ["--main", "README.rdoc"]
44
- s.extra_rdoc_files = %w(LICENSE Rakefile README.rdoc CHANGES.txt)
45
- s.add_dependency("builder", [">= 2.1.2"])
46
- end
@@ -1,18 +0,0 @@
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 'helper'
6
- require 'http_client/test_methods'
7
-
8
- class CurbTest < RSolrBaseTest
9
-
10
- def setup
11
- @c ||= RSolr::HTTPClient::connect(:curb, :url=>URL)
12
- end
13
-
14
- include HTTPClientTestMethods
15
-
16
- end
17
-
18
- end
@@ -1,12 +0,0 @@
1
- require 'helper'
2
- require 'http_client/test_methods'
3
-
4
- class NetHTTPTest < RSolrBaseTest
5
-
6
- def setup
7
- @c ||= RSolr::HTTPClient::connect(:url=>URL)
8
- end
9
-
10
- include HTTPClientTestMethods
11
-
12
- end