solr_wrapper 0.12.1 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/solr_wrapper.rb +2 -1
- data/lib/solr_wrapper/client.rb +36 -0
- data/lib/solr_wrapper/instance.rb +8 -0
- data/lib/solr_wrapper/settings.rb +16 -4
- data/lib/solr_wrapper/version.rb +1 -1
- data/solr_wrapper.gemspec +2 -0
- data/spec/lib/solr_wrapper/client_spec.rb +25 -0
- data/spec/lib/solr_wrapper/instance_spec.rb +30 -1
- data/spec/spec_helper.rb +1 -0
- metadata +35 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46083a390cb490449cea481a9ea8b3e994d0ad5f
|
4
|
+
data.tar.gz: be741be5a4f756ed77ea3a689dc7b74daa8fdedc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 278a2fbd55ade0e57220c315a82d7dc403583821e6692393b41edea331e9aafe7d48a8e9847fa76cc87911aa9c41adf79241a5572dea5ac49829b6cca31d5f9f
|
7
|
+
data.tar.gz: 3de884dae0e77ca16d8eab23a45b6e159282e87ad3a8c4a373e1a5c376abbf68d370f031acce31c39c40e56734e2326ece54ae4c75cc6d1e8565b92ef194b7cc
|
data/lib/solr_wrapper.rb
CHANGED
@@ -4,10 +4,11 @@ require 'solr_wrapper/settings'
|
|
4
4
|
require 'solr_wrapper/md5'
|
5
5
|
require 'solr_wrapper/downloader'
|
6
6
|
require 'solr_wrapper/instance'
|
7
|
+
require 'solr_wrapper/client'
|
7
8
|
|
8
9
|
module SolrWrapper
|
9
10
|
def self.default_solr_version
|
10
|
-
'6.0
|
11
|
+
'6.1.0'
|
11
12
|
end
|
12
13
|
|
13
14
|
def self.default_solr_port
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module SolrWrapper
|
5
|
+
# Solr REST API client to get status information
|
6
|
+
class Client
|
7
|
+
attr_reader :url
|
8
|
+
|
9
|
+
def initialize(url)
|
10
|
+
@url = url
|
11
|
+
end
|
12
|
+
|
13
|
+
# Check if a core or collection exists
|
14
|
+
def exists?(core_or_collection_name)
|
15
|
+
collection?(core_or_collection_name) || core?(core_or_collection_name)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def collection?(name)
|
21
|
+
response = conn.get('admin/collections?action=LIST&wt=json')
|
22
|
+
data = JSON.parse(response.body)
|
23
|
+
return if data['error'] && data['error']['msg'] == 'Solr instance is not running in SolrCloud mode.'
|
24
|
+
data['collections'].include? name
|
25
|
+
end
|
26
|
+
|
27
|
+
def core?(name)
|
28
|
+
response = conn.get('admin/cores?action=STATUS&wt=json&core=' + name)
|
29
|
+
!JSON.parse(response.body)['status'][name].empty?
|
30
|
+
end
|
31
|
+
|
32
|
+
def conn
|
33
|
+
@conn ||= Faraday.new(url: url)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -147,6 +147,10 @@ module SolrWrapper
|
|
147
147
|
create_options[:c] = options[:name] if options[:name]
|
148
148
|
create_options[:n] = options[:config_name] if options[:config_name]
|
149
149
|
create_options[:d] = options[:dir] if options[:dir]
|
150
|
+
|
151
|
+
# short-circuit if we're using persisted data with an existing core/collection
|
152
|
+
return if options[:persist] && create_options[:c] && client.exists?(create_options[:c])
|
153
|
+
|
150
154
|
exec("create", create_options)
|
151
155
|
|
152
156
|
options[:name]
|
@@ -381,6 +385,10 @@ module SolrWrapper
|
|
381
385
|
"#{config.zookeeper_host}:#{config.zookeeper_port}" if config.cloud
|
382
386
|
end
|
383
387
|
|
388
|
+
def client
|
389
|
+
SolrWrapper::Client.new(url)
|
390
|
+
end
|
391
|
+
|
384
392
|
def raise_error_unless_extracted
|
385
393
|
raise RuntimeError, "there is no solr instance at #{config.instance_dir}. Run SolrWrapper.extract first." unless extracted?
|
386
394
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'delegate'
|
2
|
+
require 'faraday'
|
2
3
|
|
3
4
|
module SolrWrapper
|
4
5
|
# Configuraton that comes from static and dynamic sources.
|
@@ -108,15 +109,26 @@ module SolrWrapper
|
|
108
109
|
@download_dir
|
109
110
|
end
|
110
111
|
|
111
|
-
|
112
112
|
def default_download_url
|
113
113
|
@default_url ||= begin
|
114
114
|
json = open(static_config.mirror_url).read
|
115
115
|
doc = JSON.parse(json)
|
116
|
-
doc['preferred'] + doc['path_info']
|
116
|
+
url = doc['preferred'] + doc['path_info']
|
117
|
+
|
118
|
+
response = Faraday.head(url)
|
119
|
+
|
120
|
+
if response.success?
|
121
|
+
url
|
122
|
+
else
|
123
|
+
archive_download_url
|
124
|
+
end
|
117
125
|
end
|
118
|
-
rescue SocketError
|
119
|
-
|
126
|
+
rescue SocketError, Faraday::Error
|
127
|
+
archive_download_url
|
128
|
+
end
|
129
|
+
|
130
|
+
def archive_download_url
|
131
|
+
"http://archive.apache.org/dist/lucene/solr/#{static_config.version}/solr-#{static_config.version}.zip"
|
120
132
|
end
|
121
133
|
|
122
134
|
def random_open_port
|
data/lib/solr_wrapper/version.rb
CHANGED
data/solr_wrapper.gemspec
CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.add_dependency "faraday"
|
21
22
|
spec.add_dependency "rubyzip"
|
22
23
|
spec.add_dependency "ruby-progressbar"
|
23
24
|
|
@@ -27,4 +28,5 @@ Gem::Specification.new do |spec|
|
|
27
28
|
spec.add_development_dependency "rspec"
|
28
29
|
spec.add_development_dependency "simple_solr_client"
|
29
30
|
spec.add_development_dependency "coveralls"
|
31
|
+
spec.add_development_dependency "fakeweb"
|
30
32
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SolrWrapper::Client do
|
4
|
+
subject { described_class.new('http://localhost:8983/solr/') }
|
5
|
+
|
6
|
+
describe '#exists?' do
|
7
|
+
it 'checks if a solrcloud collection exists' do
|
8
|
+
FakeWeb.register_uri(:get, 'http://localhost:8983/solr/admin/collections?action=LIST&wt=json', body: '{ "collections": ["x", "y", "z"]}')
|
9
|
+
FakeWeb.register_uri(:get, 'http://localhost:8983/solr/admin/cores?action=STATUS&wt=json&core=a', body: '{ "status": { "a": {} } }')
|
10
|
+
|
11
|
+
expect(subject.exists?('x')).to eq true
|
12
|
+
expect(subject.exists?('a')).to eq false
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'checks if a solr core exists' do
|
16
|
+
FakeWeb.register_uri(:get, 'http://localhost:8983/solr/admin/collections?action=LIST&wt=json', body: '{ "error": { "msg": "Solr instance is not running in SolrCloud mode."} }')
|
17
|
+
|
18
|
+
FakeWeb.register_uri(:get, 'http://localhost:8983/solr/admin/cores?action=STATUS&wt=json&core=x', body: '{ "status": { "x": { "name": "x" } } }')
|
19
|
+
FakeWeb.register_uri(:get, 'http://localhost:8983/solr/admin/cores?action=STATUS&wt=json&core=a', body: '{ "status": { "a": {} } }')
|
20
|
+
|
21
|
+
expect(subject.exists?('x')).to eq true
|
22
|
+
expect(subject.exists?('a')).to eq false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -42,6 +42,35 @@ describe SolrWrapper::Instance do
|
|
42
42
|
expect(solr_instance).not_to receive(:delete)
|
43
43
|
solr_instance.with_collection(name: 'project-development', dir: 'solr/config/', persist: true) {}
|
44
44
|
end
|
45
|
+
|
46
|
+
describe 'single solr node' do
|
47
|
+
it 'allows persistent collection on restart' do
|
48
|
+
subject.wrap do |solr|
|
49
|
+
solr.with_collection(name: 'solr-node-persistent-core', dir: File.join(FIXTURES_DIR, 'basic_configs'), persist: true) {}
|
50
|
+
end
|
51
|
+
|
52
|
+
subject.wrap do |solr|
|
53
|
+
solr.with_collection(name: 'solr-node-persistent-core', dir: File.join(FIXTURES_DIR, 'basic_configs'), persist: true) {}
|
54
|
+
solr.delete 'solr-node-persistent-core'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'solr cloud' do
|
60
|
+
let(:options) { { cloud: true } }
|
61
|
+
|
62
|
+
it 'allows persistent collection on restart' do
|
63
|
+
subject.wrap do |solr|
|
64
|
+
config_name = solr.upconfig dir: File.join(FIXTURES_DIR, 'basic_configs')
|
65
|
+
solr.with_collection(name: 'solr-cloud-persistent-collection', config_name: config_name, persist: true) {}
|
66
|
+
end
|
67
|
+
|
68
|
+
subject.wrap do |solr|
|
69
|
+
solr.with_collection(name: 'solr-cloud-persistent-collection', persist: true) {}
|
70
|
+
solr.delete 'solr-cloud-persistent-collection'
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
45
74
|
end
|
46
75
|
end
|
47
76
|
|
@@ -123,7 +152,7 @@ describe SolrWrapper::Instance do
|
|
123
152
|
|
124
153
|
describe "#version" do
|
125
154
|
subject { solr_instance.version }
|
126
|
-
it { is_expected.to eq '6.0
|
155
|
+
it { is_expected.to eq '6.1.0' }
|
127
156
|
end
|
128
157
|
|
129
158
|
describe "#md5" do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solr_wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Beer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rubyzip
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,6 +122,20 @@ dependencies:
|
|
108
122
|
- - ">="
|
109
123
|
- !ruby/object:Gem::Version
|
110
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: fakeweb
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
111
139
|
description:
|
112
140
|
email:
|
113
141
|
- chris@cbeer.info
|
@@ -129,6 +157,7 @@ files:
|
|
129
157
|
- coveralls.yml
|
130
158
|
- exe/solr_wrapper
|
131
159
|
- lib/solr_wrapper.rb
|
160
|
+
- lib/solr_wrapper/client.rb
|
132
161
|
- lib/solr_wrapper/configuration.rb
|
133
162
|
- lib/solr_wrapper/downloader.rb
|
134
163
|
- lib/solr_wrapper/instance.rb
|
@@ -147,6 +176,7 @@ files:
|
|
147
176
|
- spec/fixtures/basic_configs/stopwords.txt
|
148
177
|
- spec/fixtures/basic_configs/synonyms.txt
|
149
178
|
- spec/fixtures/sample_config.yml
|
179
|
+
- spec/lib/solr_wrapper/client_spec.rb
|
150
180
|
- spec/lib/solr_wrapper/configuration_spec.rb
|
151
181
|
- spec/lib/solr_wrapper/instance_spec.rb
|
152
182
|
- spec/lib/solr_wrapper_spec.rb
|
@@ -171,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
171
201
|
version: '0'
|
172
202
|
requirements: []
|
173
203
|
rubyforge_project:
|
174
|
-
rubygems_version: 2.
|
204
|
+
rubygems_version: 2.5.1
|
175
205
|
signing_key:
|
176
206
|
specification_version: 4
|
177
207
|
summary: Solr 5 service wrapper
|
@@ -185,7 +215,9 @@ test_files:
|
|
185
215
|
- spec/fixtures/basic_configs/stopwords.txt
|
186
216
|
- spec/fixtures/basic_configs/synonyms.txt
|
187
217
|
- spec/fixtures/sample_config.yml
|
218
|
+
- spec/lib/solr_wrapper/client_spec.rb
|
188
219
|
- spec/lib/solr_wrapper/configuration_spec.rb
|
189
220
|
- spec/lib/solr_wrapper/instance_spec.rb
|
190
221
|
- spec/lib/solr_wrapper_spec.rb
|
191
222
|
- spec/spec_helper.rb
|
223
|
+
has_rdoc:
|