rsolr 2.0.0.pre1 → 2.0.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -10
- data/CHANGES.txt +11 -0
- data/Gemfile +0 -4
- data/README.rdoc +22 -4
- data/lib/rsolr.rb +16 -1
- data/lib/rsolr/client.rb +13 -25
- data/lib/rsolr/document.rb +2 -18
- data/lib/rsolr/generator.rb +5 -0
- data/lib/rsolr/json.rb +10 -2
- data/lib/rsolr/response.rb +2 -2
- data/lib/rsolr/uri.rb +1 -1
- data/lib/rsolr/version.rb +1 -1
- data/lib/rsolr/xml.rb +9 -5
- data/rsolr.gemspec +2 -0
- data/spec/api/client_spec.rb +2 -14
- data/spec/api/json_spec.rb +14 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c12bcd80599dbe9baf6b616dd23422a935587718
|
4
|
+
data.tar.gz: ea19f8226b2a7737099c38094899a46a649e3de0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc3e492100005e174362232e5cf4b1e6d0d0e8a4288fd8810256980747288f9ff74fa61411d565610c9c234d2d638fe1c190a1c4bb35d57310b54005a1943440
|
7
|
+
data.tar.gz: 0ec2bcdf0bbcfdc8bc82d711f9c5df3158f56c948f8ae698ce07a7959aeb82534f2a202c90461003a3d99f1ce411d58b9d80e7e24ca433a1a463d6fd0b89363b
|
data/.travis.yml
CHANGED
@@ -1,21 +1,13 @@
|
|
1
|
-
addons:
|
2
|
-
apt:
|
3
|
-
packages:
|
4
|
-
- libgmp-dev
|
5
1
|
language: ruby
|
6
2
|
sudo: false
|
7
3
|
rvm:
|
8
4
|
- 2.3.1
|
9
5
|
- 2.2.5
|
10
|
-
- jruby-9.
|
11
|
-
|
12
|
-
notifications:
|
13
|
-
irc: "irc.freenode.org#blacklight"
|
14
|
-
email:
|
15
|
-
- blacklight-commits@googlegroups.com
|
6
|
+
- jruby-9.1.5.0
|
16
7
|
|
17
8
|
env:
|
18
9
|
global:
|
19
10
|
- JRUBY_OPTS="-J-Xms512m -J-Xmx1024m"
|
20
11
|
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true
|
12
|
+
|
21
13
|
jdk: oraclejdk8
|
data/CHANGES.txt
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
2.0.0.pre1
|
2
|
+
|
3
|
+
In this release, we've added many new features, including:
|
4
|
+
|
5
|
+
- a new JSON request generator (enabled by default, replacing the XML-based requests) (@mootprinter)
|
6
|
+
- using Faraday for added flexibility for HTTP configuration
|
7
|
+
- native support for nested child documents and atomic updates in RSolr::Document and RSolr::Client.add
|
8
|
+
- better support for custom field value converters (@solenko)
|
9
|
+
- removing code deprecated in RSolr 1.x (@vipulnsward, and others)
|
10
|
+
|
11
|
+
|
1
12
|
1.0.12
|
2
13
|
- Fix bug where specifying the wt property as a string, would add the supplied value to the default ('ruby') rather than overriding it.
|
3
14
|
|
data/Gemfile
CHANGED
data/README.rdoc
CHANGED
@@ -11,7 +11,6 @@ The code docs http://www.rubydoc.info/gems/rsolr
|
|
11
11
|
gem install rsolr
|
12
12
|
|
13
13
|
== Example:
|
14
|
-
require 'rubygems'
|
15
14
|
require 'rsolr'
|
16
15
|
|
17
16
|
# Direct connection
|
@@ -19,7 +18,17 @@ The code docs http://www.rubydoc.info/gems/rsolr
|
|
19
18
|
|
20
19
|
# Connecting over a proxy server
|
21
20
|
solr = RSolr.connect :url => 'http://solrserver.com', :proxy=>'http://user:pass@proxy.example.com:8080'
|
21
|
+
|
22
|
+
# Using an alternate Faraday adapter
|
23
|
+
solr = RSolr.connect :url => 'http://solrserver.com', :adapter => :em_http
|
22
24
|
|
25
|
+
# Using a custom Faraday connection
|
26
|
+
conn = Faraday.new do |faraday|
|
27
|
+
faraday.response :logger # log requests to STDOUT
|
28
|
+
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
29
|
+
end
|
30
|
+
solr = RSolr.connect conn, :url => 'http://solrserver.com'
|
31
|
+
|
23
32
|
# send a request to /select
|
24
33
|
response = solr.get 'select', :params => {:q => '*:*'}
|
25
34
|
|
@@ -34,6 +43,14 @@ The +:request+ attribute contains the original request context. You can use this
|
|
34
43
|
|
35
44
|
The +:response+ attribute contains the original response. This object contains the +:status+, +:body+ and +:headers+ keys.
|
36
45
|
|
46
|
+
== Request formats
|
47
|
+
|
48
|
+
By default, RSolr uses the Solr JSON command format for all requests.
|
49
|
+
|
50
|
+
RSolr.connect :url => 'http://solrserver.com', update_format: :json # the default
|
51
|
+
# or
|
52
|
+
RSolr.connect :url => 'http://solrserver.com', update_format: :xml
|
53
|
+
|
37
54
|
== Timeouts
|
38
55
|
The read and connect timeout settings can be set when creating a new instance of RSolr:
|
39
56
|
solr = RSolr.connect(:read_timeout => 120, :open_timeout => 120)
|
@@ -44,6 +61,7 @@ A 503 is usually a temporary error which RSolr may retry if requested. You may s
|
|
44
61
|
Only requests which specify a Retry-After header will be retried, after waiting the indicated retry interval, otherwise RSolr will treat the request as a 500. You may specify a maximum Retry-After interval to wait with the +:retry_after_limit+ option (default: one second).
|
45
62
|
solr = RSolr.connect(:retry_503 => 1, :retry_after_limit => 1)
|
46
63
|
|
64
|
+
For additional control, consider using a custom Faraday connection (see above) using its `retry` middleware.
|
47
65
|
|
48
66
|
== Querying
|
49
67
|
Use the #get / #post method to send search requests to the /select handler:
|
@@ -119,9 +137,9 @@ Multiple documents via #add
|
|
119
137
|
The optional +:add_attributes+ hash can also be used to set Solr "add" document attributes:
|
120
138
|
solr.add documents, :add_attributes => {:commitWithin => 10}
|
121
139
|
|
122
|
-
Raw
|
123
|
-
solr.update :
|
124
|
-
solr.update :
|
140
|
+
Raw commands via #update
|
141
|
+
solr.update data: '<commit/>', headers: { 'Content-Type' => 'text/xml' }
|
142
|
+
solr.update data: { optimize: true }.to_json, headers: { 'Content-Type' => 'application/json' }
|
125
143
|
|
126
144
|
When adding, you can also supply "add" xml element attributes and/or a block for manipulating other "add" related elements (docs and fields) by calling the +xml+ method directly:
|
127
145
|
|
data/lib/rsolr.rb
CHANGED
@@ -21,5 +21,20 @@ module RSolr
|
|
21
21
|
# so the result sent to Solr is ultimately a single backslash in front of the particular character
|
22
22
|
str.gsub(/([+\-&|!\(\)\{\}\[\]\^"~\*\?:\\\/])/, '\\\\\1')
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
|
+
module Array
|
26
|
+
def self.wrap(object)
|
27
|
+
if object.nil?
|
28
|
+
[]
|
29
|
+
elsif object.respond_to?(:to_ary)
|
30
|
+
object.to_ary || [object]
|
31
|
+
elsif object.is_a? Hash
|
32
|
+
[object]
|
33
|
+
elsif object.is_a? Enumerable
|
34
|
+
object
|
35
|
+
else
|
36
|
+
[object]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
25
40
|
end
|
data/lib/rsolr/client.rb
CHANGED
@@ -1,8 +1,4 @@
|
|
1
|
-
|
2
|
-
require 'json'
|
3
|
-
rescue LoadError
|
4
|
-
end
|
5
|
-
|
1
|
+
require 'json'
|
6
2
|
require 'faraday'
|
7
3
|
|
8
4
|
class RSolr::Client
|
@@ -17,7 +13,7 @@ class RSolr::Client
|
|
17
13
|
end
|
18
14
|
end
|
19
15
|
|
20
|
-
attr_reader :uri, :proxy, :options, :update_path
|
16
|
+
attr_reader :uri, :proxy, :update_format, :options, :update_path
|
21
17
|
|
22
18
|
def initialize connection, options = {}
|
23
19
|
@proxy = @uri = nil
|
@@ -34,7 +30,7 @@ class RSolr::Client
|
|
34
30
|
@proxy = false # used to avoid setting the proxy from the environment.
|
35
31
|
end
|
36
32
|
end
|
37
|
-
@update_format = options.delete(:update_format) ||
|
33
|
+
@update_format = options.delete(:update_format) || RSolr::JSON::Generator
|
38
34
|
@update_path = options.fetch(:update_path, 'update')
|
39
35
|
@options = options
|
40
36
|
end
|
@@ -83,11 +79,7 @@ class RSolr::Client
|
|
83
79
|
#
|
84
80
|
def update opts = {}
|
85
81
|
opts[:headers] ||= {}
|
86
|
-
|
87
|
-
opts[:headers]['Content-Type'] ||= 'application/json'
|
88
|
-
else
|
89
|
-
opts[:headers]['Content-Type'] ||= 'text/xml'
|
90
|
-
end
|
82
|
+
opts[:headers]['Content-Type'] ||= builder.content_type
|
91
83
|
post opts.fetch(:path, update_path), opts
|
92
84
|
end
|
93
85
|
|
@@ -155,19 +147,15 @@ class RSolr::Client
|
|
155
147
|
end
|
156
148
|
|
157
149
|
def builder
|
158
|
-
if
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
end
|
168
|
-
|
169
|
-
def json
|
170
|
-
@json ||= RSolr::JSON::Generator.new
|
150
|
+
@builder ||= if update_format.is_a? Class
|
151
|
+
update_format.new
|
152
|
+
elsif update_format == :json
|
153
|
+
RSolr::JSON::Generator.new
|
154
|
+
elsif update_format == :xml
|
155
|
+
RSolr::Xml::Generator.new
|
156
|
+
else
|
157
|
+
update_format
|
158
|
+
end
|
171
159
|
end
|
172
160
|
|
173
161
|
# +send_and_receive+ is the main request method responsible for sending requests to the +connection+ object.
|
data/lib/rsolr/document.rb
CHANGED
@@ -37,7 +37,7 @@ module RSolr
|
|
37
37
|
# document.add_field('title', 'A Title', :boost => 2.0)
|
38
38
|
#
|
39
39
|
def add_field(name, values, options = {})
|
40
|
-
wrap(values).each do |v|
|
40
|
+
RSolr::Array.wrap(values).each do |v|
|
41
41
|
next if v.nil?
|
42
42
|
|
43
43
|
field_attrs = { name: name }
|
@@ -50,26 +50,10 @@ module RSolr
|
|
50
50
|
def as_json
|
51
51
|
@fields.group_by(&:name).each_with_object({}) do |(field, values), result|
|
52
52
|
v = values.map(&:as_json)
|
53
|
-
v = v.first if v.length == 1
|
53
|
+
v = v.first if v.length == 1 && field.to_s != CHILD_DOCUMENT_KEY
|
54
54
|
result[field] = v
|
55
55
|
end
|
56
56
|
end
|
57
|
-
|
58
|
-
private
|
59
|
-
|
60
|
-
def wrap(object)
|
61
|
-
if object.nil?
|
62
|
-
[]
|
63
|
-
elsif object.respond_to?(:to_ary)
|
64
|
-
object.to_ary || [object]
|
65
|
-
elsif object.is_a? Hash
|
66
|
-
[object]
|
67
|
-
elsif object.is_a? Enumerable
|
68
|
-
object
|
69
|
-
else
|
70
|
-
[object]
|
71
|
-
end
|
72
|
-
end
|
73
57
|
end
|
74
58
|
|
75
59
|
class Field
|
data/lib/rsolr/json.rb
CHANGED
@@ -1,8 +1,16 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
1
3
|
module RSolr::JSON
|
2
|
-
class Generator
|
4
|
+
class Generator < RSolr::Generator
|
5
|
+
CONTENT_TYPE = 'application/json'.freeze
|
6
|
+
|
7
|
+
def content_type
|
8
|
+
CONTENT_TYPE
|
9
|
+
end
|
10
|
+
|
3
11
|
def add data, add_attrs = {}
|
4
12
|
add_attrs ||= {}
|
5
|
-
data =
|
13
|
+
data = RSolr::Array.wrap(data)
|
6
14
|
|
7
15
|
if add_attrs.empty? && data.none? { |doc| doc.is_a?(RSolr::Document) && !doc.attrs.empty? }
|
8
16
|
data.map do |doc|
|
data/lib/rsolr/response.rb
CHANGED
@@ -11,7 +11,7 @@ module RSolr::Response
|
|
11
11
|
@request = request
|
12
12
|
@response = response
|
13
13
|
self.merge!(result)
|
14
|
-
if self["response"] && self["response"]["docs"].is_a?(Array)
|
14
|
+
if self["response"] && self["response"]["docs"].is_a?(::Array)
|
15
15
|
docs = PaginatedDocSet.new(self["response"]["docs"])
|
16
16
|
docs.per_page = request[:params]["rows"]
|
17
17
|
docs.page_start = request[:params]["start"]
|
@@ -41,7 +41,7 @@ module RSolr::Response
|
|
41
41
|
end
|
42
42
|
|
43
43
|
# A response module which gets mixed into the solr ["response"]["docs"] array.
|
44
|
-
class PaginatedDocSet < Array
|
44
|
+
class PaginatedDocSet < ::Array
|
45
45
|
|
46
46
|
attr_accessor :page_start, :per_page, :page_total
|
47
47
|
if not (Object.const_defined?("RUBY_ENGINE") and Object::RUBY_ENGINE=='rbx')
|
data/lib/rsolr/uri.rb
CHANGED
data/lib/rsolr/version.rb
CHANGED
data/lib/rsolr/xml.rb
CHANGED
@@ -1,13 +1,10 @@
|
|
1
|
-
begin; require 'nokogiri'; rescue LoadError; end
|
2
|
-
require 'time'
|
3
|
-
|
4
1
|
module RSolr::Xml
|
5
2
|
require 'rsolr/document'
|
6
3
|
|
7
4
|
Document = RSolr::Document
|
8
5
|
Field = RSolr::Field
|
9
6
|
|
10
|
-
class Generator
|
7
|
+
class Generator < RSolr::Generator
|
11
8
|
class << self
|
12
9
|
attr_accessor :use_nokogiri
|
13
10
|
|
@@ -21,7 +18,14 @@ module RSolr::Xml
|
|
21
18
|
end
|
22
19
|
end
|
23
20
|
end
|
24
|
-
self.use_nokogiri =
|
21
|
+
self.use_nokogiri = defined?(::Nokogiri::XML::Builder) ? true : false
|
22
|
+
|
23
|
+
CONTENT_TYPE = 'text/xml'.freeze
|
24
|
+
|
25
|
+
def content_type
|
26
|
+
CONTENT_TYPE
|
27
|
+
end
|
28
|
+
|
25
29
|
|
26
30
|
def nokogiri_build &block
|
27
31
|
b = ::Nokogiri::XML::Builder.new do |xml|
|
data/rsolr.gemspec
CHANGED
data/spec/api/client_spec.rb
CHANGED
@@ -67,18 +67,6 @@ RSpec.describe RSolr::Client do
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
context "xml" do
|
71
|
-
it "should return an instance of RSolr::Xml::Generator" do
|
72
|
-
expect(client.xml).to be_a RSolr::Xml::Generator
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
context "json" do
|
77
|
-
it "should return an instance of RSolr::JSON::Generator" do
|
78
|
-
expect(client.json).to be_a RSolr::JSON::Generator
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
70
|
context "add" do
|
83
71
|
it "should send xml to the connection's #post method" do
|
84
72
|
expect(client).to receive(:execute).
|
@@ -95,7 +83,7 @@ RSpec.describe RSolr::Client do
|
|
95
83
|
:status => 200,
|
96
84
|
:headers => {"Content-Type"=>"text/xml"}
|
97
85
|
)
|
98
|
-
expect(client.
|
86
|
+
expect(client.builder).to receive(:add).
|
99
87
|
with({:id=>1}, {:commitWith=>10}).
|
100
88
|
and_return("<xml/>")
|
101
89
|
client.add({:id=>1}, :add_attributes => {:commitWith=>10})
|
@@ -119,7 +107,7 @@ RSpec.describe RSolr::Client do
|
|
119
107
|
:status => 200,
|
120
108
|
:headers => {"Content-Type"=>"text/xml"}
|
121
109
|
)
|
122
|
-
expect(client.
|
110
|
+
expect(client.builder).to receive(:add).
|
123
111
|
with({:id => 1}, {:commitWith=>10}).
|
124
112
|
and_return('{"hello":"this is json"}')
|
125
113
|
client.add({:id=>1}, :add_attributes => {:commitWith=>10})
|
data/spec/api/json_spec.rb
CHANGED
@@ -123,6 +123,20 @@ RSpec.describe RSolr::JSON do
|
|
123
123
|
expect(message.length).to eq 1
|
124
124
|
expect(message.first).to eq data
|
125
125
|
end
|
126
|
+
|
127
|
+
it 'supports nested child documents with only a single document' do
|
128
|
+
data = {
|
129
|
+
_childDocuments_: [
|
130
|
+
{
|
131
|
+
id: 1
|
132
|
+
}
|
133
|
+
]
|
134
|
+
}
|
135
|
+
|
136
|
+
message = JSON.parse(generator.add(data), symbolize_names: true)
|
137
|
+
expect(message.length).to eq 1
|
138
|
+
expect(message.first).to eq data
|
139
|
+
end
|
126
140
|
end
|
127
141
|
|
128
142
|
it 'should create multiple fields from array values' do
|
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: 2.0.0.
|
4
|
+
version: 2.0.0.pre2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Antoine Latter
|
@@ -29,7 +29,7 @@ authors:
|
|
29
29
|
autorequire:
|
30
30
|
bindir: bin
|
31
31
|
cert_chain: []
|
32
|
-
date:
|
32
|
+
date: 2017-02-05 00:00:00.000000000 Z
|
33
33
|
dependencies:
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: builder
|
@@ -164,6 +164,7 @@ files:
|
|
164
164
|
- lib/rsolr/client.rb
|
165
165
|
- lib/rsolr/document.rb
|
166
166
|
- lib/rsolr/error.rb
|
167
|
+
- lib/rsolr/generator.rb
|
167
168
|
- lib/rsolr/json.rb
|
168
169
|
- lib/rsolr/response.rb
|
169
170
|
- lib/rsolr/uri.rb
|
@@ -206,9 +207,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
206
207
|
- - ">"
|
207
208
|
- !ruby/object:Gem::Version
|
208
209
|
version: 1.3.1
|
209
|
-
requirements:
|
210
|
+
requirements:
|
211
|
+
- Apache Solr
|
210
212
|
rubyforge_project: rsolr
|
211
|
-
rubygems_version: 2.5.
|
213
|
+
rubygems_version: 2.5.2
|
212
214
|
signing_key:
|
213
215
|
specification_version: 4
|
214
216
|
summary: A Ruby client for Apache Solr
|