rsolr 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a439e2ad6e60a3ca89ef3423cd44d860222beec9
4
- data.tar.gz: d713c30d050a5e71e7e14a0707fa348ca6509325
2
+ SHA256:
3
+ metadata.gz: 3b30bc226e290ec41e124233b38c4ff9e3e2a262d7d25fb940c10952c04cdbbe
4
+ data.tar.gz: 2b0a15cdee7a2c61f9732381f7e38cd0b1345bd2d9f25efc48e57a9609af32ec
5
5
  SHA512:
6
- metadata.gz: 6730fd4ba6f8f1ed97c4bfa95b6ba0984a46da482a3aeebd4ce6a683e01cc669038319d8aba520bcd88d2c347fc4fe09d2209479b4499e94ba9aafa2d9700808
7
- data.tar.gz: 21cf5078ab027b7acd3852b7e118d532829910e844f882660e2860ed241032c75d239153d1bfcb511d0b275ca96b761d0f34eaaf5579027de47f48a93baeb81b
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
- url = options[:url] ? options[:url].dup : 'http://127.0.0.1:8983/solr/'
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  module RSolr
2
- VERSION = "2.1.0"
2
+ VERSION = "2.2.0"
3
3
 
4
4
  def self.version
5
5
  VERSION
@@ -2,7 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  RSpec.describe RSolr::Client do
4
4
  let(:connection) { nil }
5
- let(:connection_options) { { url: "http://localhost:9999/solr", read_timeout: 42, open_timeout: 43, update_format: :xml } }
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
@@ -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.1.0
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: 2017-11-15 00:00:00.000000000 Z
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.11
228
+ rubygems_version: 2.7.6
229
229
  signing_key:
230
230
  specification_version: 4
231
231
  summary: A Ruby client for Apache Solr