rsolr 1.0.0 → 1.0.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.
- data/README.rdoc +1 -1
- data/VERSION +1 -1
- data/lib/rsolr/client.rb +8 -6
- data/lib/rsolr/connection.rb +1 -1
- data/lib/rsolr/error.rb +5 -1
- data/lib/rsolr/pagination.rb +1 -0
- data/lib/rsolr-direct.rb +111 -0
- data/lib/rsolr.rb +3 -1
- data/spec/api/connection_spec.rb +10 -6
- data/spec/api/error_spec.rb +54 -2
- data/spec/spec_helper.rb +1 -1
- data/tasks/rdoc.rake +4 -2
- data/tasks/spec.rake +11 -14
- metadata +37 -7
data/README.rdoc
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
A simple, extensible Ruby client for Apache Solr.
|
4
4
|
|
5
|
-
Notice: This document is only for the the 1.0
|
5
|
+
Notice: This document is only for the the 1.0 in the master. The last pre-1.0 gem release documentation can be found here: http://github.com/mwmitchell/rsolr/tree/v0.12.1
|
6
6
|
|
7
7
|
==Documentation
|
8
8
|
The code docs can be viewed here : http://rdoc.info/projects/mwmitchell/rsolr
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.1
|
data/lib/rsolr/client.rb
CHANGED
@@ -5,12 +5,14 @@ class RSolr::Client
|
|
5
5
|
def initialize connection, options = {}
|
6
6
|
@connection = connection
|
7
7
|
unless false === options[:url]
|
8
|
-
url = options[:url]
|
8
|
+
url = options[:url] ? options[:url].dup : 'http://127.0.0.1:8983/solr/'
|
9
9
|
url << "/" unless url[-1] == ?/
|
10
|
-
proxy_url = options[:proxy]
|
11
|
-
proxy_url << "/" unless proxy_url.nil? or proxy_url[-1] == ?/
|
12
10
|
@uri = RSolr::Uri.create url
|
13
|
-
|
11
|
+
if options[:proxy]
|
12
|
+
proxy_url = options[:proxy].dup
|
13
|
+
proxy_url << "/" unless proxy_url.nil? or proxy_url[-1] == ?/
|
14
|
+
@proxy = RSolr::Uri.create proxy_url if proxy_url
|
15
|
+
end
|
14
16
|
end
|
15
17
|
@options = options
|
16
18
|
extend RSolr::Pagination::Client
|
@@ -223,7 +225,7 @@ class RSolr::Client
|
|
223
225
|
end
|
224
226
|
|
225
227
|
# evaluates the response[:body],
|
226
|
-
#
|
228
|
+
# attempts to bring the ruby string to life.
|
227
229
|
# If a SyntaxError is raised, then
|
228
230
|
# this method intercepts and raises a
|
229
231
|
# RSolr::Error::InvalidRubyResponse
|
@@ -237,4 +239,4 @@ class RSolr::Client
|
|
237
239
|
end
|
238
240
|
end
|
239
241
|
|
240
|
-
end
|
242
|
+
end
|
data/lib/rsolr/connection.rb
CHANGED
@@ -61,7 +61,7 @@ class RSolr::Connection
|
|
61
61
|
# request_context[:path],
|
62
62
|
# :file => io)
|
63
63
|
# else
|
64
|
-
raw_request = http_method.new request_context[:uri].
|
64
|
+
raw_request = http_method.new request_context[:uri].request_uri
|
65
65
|
# end
|
66
66
|
raw_request.initialize_http_header headers
|
67
67
|
raw_request
|
data/lib/rsolr/error.rb
CHANGED
@@ -25,6 +25,10 @@ module RSolr::Error
|
|
25
25
|
def parse_solr_error_response body
|
26
26
|
begin
|
27
27
|
info = body.scan(/<pre>(.*)<\/pre>/mi)[0]
|
28
|
+
info = info.join if info.respond_to? :join
|
29
|
+
|
30
|
+
info ||= body # body may not contain <pre> elements
|
31
|
+
|
28
32
|
partial = info.to_s.split("\n")[0..10]
|
29
33
|
partial.join("\n").gsub(">", ">").gsub("<", "<")
|
30
34
|
rescue
|
@@ -110,4 +114,4 @@ module RSolr::Error
|
|
110
114
|
|
111
115
|
end
|
112
116
|
|
113
|
-
end
|
117
|
+
end
|
data/lib/rsolr/pagination.rb
CHANGED
@@ -17,6 +17,7 @@ module RSolr::Pagination
|
|
17
17
|
|
18
18
|
# A paginated request method.
|
19
19
|
def paginate page, per_page, path, opts = nil
|
20
|
+
warn "DEPRECATION WARNING: RSolr::Pagination / pagination functionality will be removed in 1.1.0. It will instead be available in RSolr::Ext 1.1.0"
|
20
21
|
request_context = build_paginated_request page, per_page, path, opts
|
21
22
|
execute request_context
|
22
23
|
end
|
data/lib/rsolr-direct.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'java'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rsolr'
|
4
|
+
|
5
|
+
#
|
6
|
+
# Connection for JRuby + DirectSolrConnection
|
7
|
+
#
|
8
|
+
module RSolr::Direct
|
9
|
+
|
10
|
+
# load the java libs that ship with rsolr-direct
|
11
|
+
# RSolr.load_java_libs
|
12
|
+
# rsolr = RSolr.connect :direct, :solr_home => ''
|
13
|
+
def self.load_java_libs apache_solr_dir
|
14
|
+
@java_libs_loaded ||= (
|
15
|
+
base_dir = File.expand_path(apache_solr_dir)
|
16
|
+
['lib', 'dist'].each do |sub|
|
17
|
+
Dir[File.join(base_dir, sub, '*.jar')].each do |jar|
|
18
|
+
require jar
|
19
|
+
end
|
20
|
+
end
|
21
|
+
true
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
RSolr.class_eval do
|
26
|
+
# RSolr.direct_connect :solr_home => 'apache-solr/example/solr'
|
27
|
+
# RSolr.direct_connect java_solr_core
|
28
|
+
# RSolr.direct_connect java_direct_solr_connection
|
29
|
+
def self.direct_connect *args, &blk
|
30
|
+
client = RSolr::Client.new RSolr::Direct::Connection.new(*args), {:url => false}
|
31
|
+
if block_given?
|
32
|
+
yield client
|
33
|
+
client.connection.close
|
34
|
+
nil
|
35
|
+
else
|
36
|
+
client
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class Connection
|
42
|
+
|
43
|
+
attr_accessor :opts
|
44
|
+
|
45
|
+
class MissingRequiredJavaLibs < RuntimeError
|
46
|
+
end
|
47
|
+
|
48
|
+
class InvalidSolrHome < RuntimeError
|
49
|
+
end
|
50
|
+
|
51
|
+
# opts can be an instance of org.apache.solr.servlet.DirectSolrConnection
|
52
|
+
# if opts is NOT an instance of org.apache.solr.servlet.DirectSolrConnection
|
53
|
+
# then...
|
54
|
+
# required: opts[:solr_home] is absolute path to solr home (the directory with "data", "config" etc.)
|
55
|
+
def initialize opts
|
56
|
+
begin
|
57
|
+
org.apache.solr.servlet.DirectSolrConnection
|
58
|
+
rescue NameError
|
59
|
+
raise MissingRequiredJavaLibs
|
60
|
+
end
|
61
|
+
if opts.is_a?(Hash) and opts[:solr_home]
|
62
|
+
raise InvalidSolrHome unless File.exists?(opts[:solr_home])
|
63
|
+
opts[:data_dir] ||= File.join(opts[:solr_home], 'data')
|
64
|
+
@opts = opts
|
65
|
+
elsif opts.class.to_s == "Java::OrgApacheSolrCore::SolrCore"
|
66
|
+
@direct = org.apache.solr.servlet.DirectSolrConnection.new(opts)
|
67
|
+
elsif opts.class.to_s == "Java::OrgApacheSolrServlet::DirectSolrConnection"
|
68
|
+
@direct = opts
|
69
|
+
end
|
70
|
+
opts[:auto_connect] = true unless opts.key?(:auto_connect)
|
71
|
+
self.direct if opts[:auto_connect]
|
72
|
+
end
|
73
|
+
|
74
|
+
# sets the @direct instance variable if it has not yet been set
|
75
|
+
def direct
|
76
|
+
@direct ||= org.apache.solr.servlet.DirectSolrConnection.new(opts[:solr_home], @opts[:data_dir], nil)
|
77
|
+
end
|
78
|
+
|
79
|
+
# rsolr.connection.open
|
80
|
+
alias_method :open, :direct
|
81
|
+
|
82
|
+
def close
|
83
|
+
if @direct
|
84
|
+
@direct.close
|
85
|
+
@direct = nil
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# send a request to the connection
|
90
|
+
def execute client, request_context
|
91
|
+
#data = request_context[:data]
|
92
|
+
#data = data.to_xml if data.respond_to?(:to_xml)
|
93
|
+
url = [request_context[:path], request_context[:query]].join("?")
|
94
|
+
url = "/" + url unless url[0].chr == "/"
|
95
|
+
begin
|
96
|
+
body = direct.request(url, request_context[:data])
|
97
|
+
rescue
|
98
|
+
$!.extend RSolr::Error::SolrContext
|
99
|
+
$!.request = request_context
|
100
|
+
raise $!
|
101
|
+
end
|
102
|
+
{
|
103
|
+
:status => 200,
|
104
|
+
:body => body,
|
105
|
+
:headers => {}
|
106
|
+
}
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
data/lib/rsolr.rb
CHANGED
@@ -13,7 +13,9 @@ module RSolr
|
|
13
13
|
VERSION = self.version
|
14
14
|
|
15
15
|
def self.connect *args
|
16
|
-
|
16
|
+
driver = Class === args[0] ? args[0] : RSolr::Connection
|
17
|
+
opts = Hash === args[-1] ? args[-1] : {}
|
18
|
+
Client.new driver.new, opts
|
17
19
|
end
|
18
20
|
|
19
21
|
# RSolr.escape
|
data/spec/api/connection_spec.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
describe "RSolr::Connection" do
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
context "setup_raw_request" do
|
5
|
+
c = RSolr::Connection.new
|
6
|
+
base_url = "http://localhost:8983/solr"
|
7
|
+
client = RSolr::Client.new c, :url => base_url
|
8
|
+
req = c.send :setup_raw_request, {:headers => {"content-type" => "text/xml"}, :method => :get, :uri => URI.parse(base_url + "/select?q=*:*")}
|
9
|
+
req.path.should == "/solr/select?q=*:*"
|
10
|
+
headers = {}
|
11
|
+
req.each_header{|k,v| headers[k] = v}
|
12
|
+
headers.should == {"content-type"=>"text/xml"}
|
13
|
+
end
|
10
14
|
|
11
15
|
end
|
data/spec/api/error_spec.rb
CHANGED
@@ -1,4 +1,56 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
describe "RSolr::Error" do
|
3
|
-
|
4
|
-
|
3
|
+
def generate_error_with_backtrace(request, response)
|
4
|
+
raise RSolr::Error::Http.new request, response
|
5
|
+
rescue RSolr::Error::Http => exception
|
6
|
+
exception
|
7
|
+
end
|
8
|
+
|
9
|
+
context "when the response body is wrapped in a <pre> element" do
|
10
|
+
before do
|
11
|
+
response_lines = (1..15).to_a.map { |i| "line #{i}" }
|
12
|
+
|
13
|
+
@request = mock :[] => "mocked"
|
14
|
+
@response = {
|
15
|
+
:body => "<pre>" + response_lines.join("\n") + "</pre>",
|
16
|
+
:status => 400
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
it "only shows the first eleven lines of the response" do
|
21
|
+
error = generate_error_with_backtrace @request, @response
|
22
|
+
error.to_s.should match(/line 1\n.+line 11\n\n/m)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "shows only one line when the response is one line long" do
|
26
|
+
@response[:body] = "<pre>failed</pre>"
|
27
|
+
|
28
|
+
error = generate_error_with_backtrace @request, @response
|
29
|
+
error.to_s.should match(/Error: failed/)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when the response body is not wrapped in a <pre> element" do
|
34
|
+
before do
|
35
|
+
response_lines = (1..15).to_a.map { |i| "line #{i}" }
|
36
|
+
|
37
|
+
@request = mock :[] => "mocked"
|
38
|
+
@response = {
|
39
|
+
:body => response_lines.join("\n"),
|
40
|
+
:status => 400
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
it "only shows the first eleven lines of the response" do
|
45
|
+
error = generate_error_with_backtrace @request, @response
|
46
|
+
error.to_s.should match(/line 1\n.+line 11\n\n/m)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "shows only one line when the response is one line long" do
|
50
|
+
@response[:body] = "failed"
|
51
|
+
|
52
|
+
error = generate_error_with_backtrace @request, @response
|
53
|
+
error.to_s.should match(/Error: failed/)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require File.
|
1
|
+
require File.expand_path('../../lib/rsolr', __FILE__)
|
data/tasks/rdoc.rake
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
# Rdoc
|
2
|
+
require "rdoc/task"
|
3
|
+
|
2
4
|
desc 'Generate documentation for the rsolr gem.'
|
3
|
-
|
5
|
+
RDoc::Task.new(:doc) do |rdoc|
|
4
6
|
rdoc.rdoc_dir = 'doc'
|
5
7
|
rdoc.title = 'RSolr'
|
6
8
|
rdoc.options << '--line-numbers' << '--inline-source'
|
7
9
|
rdoc.rdoc_files.include('README.rdoc')
|
8
10
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
9
|
-
end
|
11
|
+
end
|
data/tasks/spec.rake
CHANGED
@@ -1,9 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
require 'spec'
|
6
|
-
require 'spec/rake/spectask'
|
1
|
+
require "rubygems"
|
2
|
+
require 'rspec'
|
3
|
+
require 'rspec/core/rake_task'
|
7
4
|
|
8
5
|
namespace :spec do
|
9
6
|
|
@@ -20,23 +17,23 @@ namespace :spec do
|
|
20
17
|
end
|
21
18
|
|
22
19
|
desc 'run api specs (mock out Solr dependency)'
|
23
|
-
|
20
|
+
RSpec::Core::RakeTask.new(:api) do |t|
|
24
21
|
|
25
|
-
t.
|
26
|
-
t.
|
22
|
+
t.pattern = [File.join('spec', 'spec_helper.rb')]
|
23
|
+
t.pattern += FileList[File.join('spec', 'api', '**', '*_spec.rb')]
|
27
24
|
|
28
25
|
t.verbose = true
|
29
|
-
t.
|
26
|
+
t.rspec_opts = ['--color']
|
30
27
|
end
|
31
28
|
|
32
29
|
desc 'run integration specs'
|
33
|
-
|
30
|
+
RSpec::Core::RakeTask.new(:integration) do |t|
|
34
31
|
|
35
|
-
t.
|
36
|
-
t.
|
32
|
+
t.pattern = [File.join('spec', 'spec_helper.rb')]
|
33
|
+
t.pattern += FileList[File.join('spec', 'integration', '**', '*_spec.rb')]
|
37
34
|
|
38
35
|
t.verbose = true
|
39
|
-
t.
|
36
|
+
t.rspec_opts = ['--color']
|
40
37
|
end
|
41
38
|
|
42
39
|
end
|
metadata
CHANGED
@@ -1,29 +1,42 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rsolr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 21
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 1
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Matt Mitchell
|
14
|
+
- Jeremy Hinegardner
|
15
|
+
- Mat Brown
|
16
|
+
- Mike Perham
|
17
|
+
- Nathan Witmer
|
18
|
+
- Peter Kieltyka
|
19
|
+
- Randy Souza
|
20
|
+
- shairon toledo
|
21
|
+
- shima
|
22
|
+
- Chris Beer
|
23
|
+
- Jonathan Rochkind
|
13
24
|
autorequire:
|
14
25
|
bindir: bin
|
15
26
|
cert_chain: []
|
16
27
|
|
17
|
-
date: 2011-
|
28
|
+
date: 2011-05-23 00:00:00 -04:00
|
18
29
|
default_executable:
|
19
30
|
dependencies:
|
20
31
|
- !ruby/object:Gem::Dependency
|
21
32
|
name: builder
|
22
33
|
prerelease: false
|
23
34
|
requirement: &id001 !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
24
36
|
requirements:
|
25
37
|
- - ">="
|
26
38
|
- !ruby/object:Gem::Version
|
39
|
+
hash: 15
|
27
40
|
segments:
|
28
41
|
- 2
|
29
42
|
- 1
|
@@ -44,6 +57,7 @@ files:
|
|
44
57
|
- LICENSE
|
45
58
|
- README.rdoc
|
46
59
|
- VERSION
|
60
|
+
- lib/rsolr-direct.rb
|
47
61
|
- lib/rsolr.rb
|
48
62
|
- lib/rsolr/char.rb
|
49
63
|
- lib/rsolr/client.rb
|
@@ -52,33 +66,49 @@ files:
|
|
52
66
|
- lib/rsolr/pagination.rb
|
53
67
|
- lib/rsolr/uri.rb
|
54
68
|
- lib/rsolr/xml.rb
|
69
|
+
- spec/api/char_spec.rb
|
70
|
+
- spec/api/client_spec.rb
|
71
|
+
- spec/api/connection_spec.rb
|
72
|
+
- spec/api/error_spec.rb
|
73
|
+
- spec/api/pagination_spec.rb
|
74
|
+
- spec/api/rsolr_spec.rb
|
75
|
+
- spec/api/uri_spec.rb
|
76
|
+
- spec/api/xml_spec.rb
|
77
|
+
- spec/spec_helper.rb
|
78
|
+
- Rakefile
|
79
|
+
- tasks/spec.rake
|
80
|
+
- tasks/rdoc.rake
|
55
81
|
has_rdoc: true
|
56
82
|
homepage: http://github.com/mwmitchell/rsolr
|
57
83
|
licenses: []
|
58
84
|
|
59
85
|
post_install_message:
|
60
|
-
rdoc_options:
|
61
|
-
|
86
|
+
rdoc_options: []
|
87
|
+
|
62
88
|
require_paths:
|
63
89
|
- lib
|
64
90
|
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
65
92
|
requirements:
|
66
93
|
- - ">="
|
67
94
|
- !ruby/object:Gem::Version
|
95
|
+
hash: 3
|
68
96
|
segments:
|
69
97
|
- 0
|
70
98
|
version: "0"
|
71
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
72
101
|
requirements:
|
73
102
|
- - ">="
|
74
103
|
- !ruby/object:Gem::Version
|
104
|
+
hash: 3
|
75
105
|
segments:
|
76
106
|
- 0
|
77
107
|
version: "0"
|
78
108
|
requirements: []
|
79
109
|
|
80
110
|
rubyforge_project:
|
81
|
-
rubygems_version: 1.
|
111
|
+
rubygems_version: 1.6.2
|
82
112
|
signing_key:
|
83
113
|
specification_version: 3
|
84
114
|
summary: A Ruby client for Apache Solr
|