rsolr 2.1.0 → 2.2.0
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.
- checksums.yaml +5 -5
- data/lib/rsolr/client.rb +13 -3
- data/lib/rsolr/document.rb +3 -0
- data/lib/rsolr/version.rb +1 -1
- data/spec/api/client_spec.rb +19 -1
- data/spec/api/json_spec.rb +8 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3b30bc226e290ec41e124233b38c4ff9e3e2a262d7d25fb940c10952c04cdbbe
|
4
|
+
data.tar.gz: 2b0a15cdee7a2c61f9732381f7e38cd0b1345bd2d9f25efc48e57a9609af32ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 168b8ba13fa7eedfdba1de36af07e1a65d59545506368573423470a075740d47b5e025dc6ba9f78b74fc6b945d24f3a9bca8b3fdf97469644e7480459db1c115
|
7
|
+
data.tar.gz: 2f4b142ff6b729451bfbac58c49775c8bc221dbaee074e9417ce1edd28ebaf5f8c07687286b001ef5411d35e6a9915fa48d4d3db585a6b6b90ac2b1c25b16129
|
data/lib/rsolr/client.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'json'
|
2
4
|
require 'faraday'
|
3
5
|
require 'uri'
|
4
6
|
|
5
7
|
class RSolr::Client
|
8
|
+
DEFAULT_URL = 'http://127.0.0.1:8983/solr/'
|
6
9
|
|
7
10
|
class << self
|
8
11
|
def default_wt
|
@@ -20,9 +23,7 @@ class RSolr::Client
|
|
20
23
|
@proxy = @uri = nil
|
21
24
|
@connection = connection
|
22
25
|
unless false === options[:url]
|
23
|
-
|
24
|
-
url << "/" unless url[-1] == ?/
|
25
|
-
@uri = ::URI.parse(url)
|
26
|
+
@uri = extract_url_from_options(options)
|
26
27
|
if options[:proxy]
|
27
28
|
proxy_url = options[:proxy].dup
|
28
29
|
proxy_url << "/" unless proxy_url.nil? or proxy_url[-1] == ?/
|
@@ -36,6 +37,15 @@ class RSolr::Client
|
|
36
37
|
@options = options
|
37
38
|
end
|
38
39
|
|
40
|
+
def extract_url_from_options(options)
|
41
|
+
url = options[:url] ? options[:url].dup : DEFAULT_URL
|
42
|
+
url << "/" unless url[-1] == ?/
|
43
|
+
uri = ::URI.parse(url)
|
44
|
+
# URI::HTTPS is a subclass of URI::HTTP, so this check accepts HTTP(S)
|
45
|
+
raise ArgumentError, "You must provide an HTTP(S) url." unless uri.kind_of?(URI::HTTP)
|
46
|
+
uri
|
47
|
+
end
|
48
|
+
|
39
49
|
# returns the request uri object.
|
40
50
|
def base_request_uri
|
41
51
|
base_uri.request_uri if base_uri
|
data/lib/rsolr/document.rb
CHANGED
@@ -48,6 +48,9 @@ module RSolr
|
|
48
48
|
def as_json
|
49
49
|
@fields.group_by(&:name).each_with_object({}) do |(field, values), result|
|
50
50
|
v = values.map(&:as_json)
|
51
|
+
if v.length > 1 && v.first.is_a?(Hash) && v.first[:value]
|
52
|
+
v = v.first.merge(value: v.map { |single| single[:value] })
|
53
|
+
end
|
51
54
|
v = v.first if v.length == 1 && field.to_s != CHILD_DOCUMENT_KEY
|
52
55
|
result[field] = v
|
53
56
|
end
|
data/lib/rsolr/version.rb
CHANGED
data/spec/api/client_spec.rb
CHANGED
@@ -2,7 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
RSpec.describe RSolr::Client do
|
4
4
|
let(:connection) { nil }
|
5
|
-
let(:
|
5
|
+
let(:url) { "http://localhost:9999/solr" }
|
6
|
+
let(:connection_options) { { url: url, read_timeout: 42, open_timeout: 43, update_format: :xml } }
|
6
7
|
|
7
8
|
let(:client) do
|
8
9
|
RSolr::Client.new connection, connection_options
|
@@ -41,6 +42,23 @@ RSpec.describe RSolr::Client do
|
|
41
42
|
client = RSolr::Client.new(:whatevs, { proxy: false })
|
42
43
|
expect(client.proxy).to eq(false)
|
43
44
|
end
|
45
|
+
|
46
|
+
context "with an non-HTTP url" do
|
47
|
+
let(:url) { "fake://localhost:9999/solr" }
|
48
|
+
|
49
|
+
it "raises an argument error" do
|
50
|
+
expect { client }.to raise_error ArgumentError, "You must provide an HTTP(S) url."
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "with an HTTPS url" do
|
55
|
+
let(:url) { "https://localhost:9999/solr" }
|
56
|
+
|
57
|
+
it "creates a connection" do
|
58
|
+
expect(client.uri).to be_kind_of URI::HTTPS
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
44
62
|
end
|
45
63
|
|
46
64
|
context "send_and_receive" do
|
data/spec/api/json_spec.rb
CHANGED
@@ -149,6 +149,14 @@ RSpec.describe RSolr::JSON do
|
|
149
149
|
expect(message.first).to eq data
|
150
150
|
end
|
151
151
|
|
152
|
+
it 'should create multiple fields from array values with options' do
|
153
|
+
message = JSON.parse(
|
154
|
+
generator.add(id: '1') { |doc| doc.add_field(:name, %w[matt1 matt2], boost: 3) },
|
155
|
+
symbolize_names: true
|
156
|
+
)
|
157
|
+
expect(message).to eq [{ id: '1', name: { boost: 3, value: %w[matt1 matt2] } }]
|
158
|
+
end
|
159
|
+
|
152
160
|
describe '#commit' do
|
153
161
|
it 'generates a commit command' do
|
154
162
|
expect(JSON.parse(generator.commit, symbolize_names: true)).to eq(commit: {})
|
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.
|
4
|
+
version: 2.2.0
|
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: 2018-05-09 00:00:00.000000000 Z
|
33
33
|
dependencies:
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: builder
|
@@ -225,7 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
225
225
|
requirements:
|
226
226
|
- Apache Solr
|
227
227
|
rubyforge_project: rsolr
|
228
|
-
rubygems_version: 2.6
|
228
|
+
rubygems_version: 2.7.6
|
229
229
|
signing_key:
|
230
230
|
specification_version: 4
|
231
231
|
summary: A Ruby client for Apache Solr
|