solr_wrapper 0.7.0 → 0.8.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 +4 -4
- data/.travis.yml +6 -2
- data/lib/solr_wrapper/configuration.rb +33 -17
- data/lib/solr_wrapper/downloader.rb +15 -9
- data/lib/solr_wrapper/instance.rb +1 -1
- data/lib/solr_wrapper/settings.rb +2 -0
- data/lib/solr_wrapper/version.rb +1 -1
- data/lib/solr_wrapper.rb +1 -1
- data/spec/fixtures/sample_config.yml +4 -0
- data/spec/lib/solr_wrapper/configuration_spec.rb +20 -0
- data/spec/lib/solr_wrapper/instance_spec.rb +23 -8
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 26e84bf462a67bf41bcc28be718464861ce482d8
|
|
4
|
+
data.tar.gz: c38874bc575bfe27d3481ea5e6b61d8f9da28ca1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 28ade5c8d559625c6d584202ecdd9ce5ca0bc55d2e49fe3bfe3480629df45e766311986cf8d0a1ba80d2f1b3826094c18014c8e2dd3e754702067391d726846f
|
|
7
|
+
data.tar.gz: fc164fb6434984bd6c6f05964a2755b08c71c303480542dea0da5149dc0c3e60d79eb61c74afaafb8aa44a591baba8a728bb4420f34ca91055918b7ee38c064a
|
data/.travis.yml
CHANGED
|
@@ -3,8 +3,8 @@ module SolrWrapper
|
|
|
3
3
|
attr_reader :options
|
|
4
4
|
|
|
5
5
|
def initialize(options)
|
|
6
|
-
@options = options
|
|
7
|
-
|
|
6
|
+
@options = read_config(options[:config], options[:verbose])
|
|
7
|
+
.merge options
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def solr_xml
|
|
@@ -35,7 +35,7 @@ module SolrWrapper
|
|
|
35
35
|
# Check if the port option has been explicitly set to nil.
|
|
36
36
|
# this means to start solr wrapper on a random open port
|
|
37
37
|
return nil if options.key?(:port) && !options[:port]
|
|
38
|
-
options
|
|
38
|
+
options.fetch(:port) { SolrWrapper.default_instance_options[:port] }.to_s
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
def download_path
|
|
@@ -78,27 +78,43 @@ module SolrWrapper
|
|
|
78
78
|
options[:version_file]
|
|
79
79
|
end
|
|
80
80
|
|
|
81
|
+
def collection_options
|
|
82
|
+
hash = options.fetch(:collection, {})
|
|
83
|
+
Configuration.slice(convert_keys(hash), :name, :dir)
|
|
84
|
+
end
|
|
85
|
+
|
|
81
86
|
private
|
|
82
87
|
|
|
83
|
-
def
|
|
84
|
-
|
|
88
|
+
def self.slice(source, *keys)
|
|
89
|
+
keys.each_with_object({}) { |k, hash| hash[k] = source[k] if source.has_key?(k) }
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def read_config(config_file, verbose)
|
|
85
93
|
default_configuration_paths.each do |p|
|
|
86
94
|
path = File.expand_path(p)
|
|
87
|
-
|
|
95
|
+
config_file ||= path if File.exist? path
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
unless config_file
|
|
99
|
+
$stdout.puts "No config specified" if verbose
|
|
100
|
+
return {}
|
|
88
101
|
end
|
|
89
102
|
|
|
90
|
-
if
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return
|
|
96
|
-
end
|
|
97
|
-
collection_config = config.delete(:collection) || {}
|
|
98
|
-
@options = config.merge(options)
|
|
99
|
-
elsif verbose?
|
|
100
|
-
$stdout.puts "No config specified"
|
|
103
|
+
$stdout.puts "Loading configuration from #{config_file}" if verbose
|
|
104
|
+
config = YAML.load(ERB.new(IO.read(config_file)).result(binding))
|
|
105
|
+
unless config
|
|
106
|
+
$stderr.puts "Unable to parse config #{config_file}" if verbose
|
|
107
|
+
return {}
|
|
101
108
|
end
|
|
109
|
+
convert_keys(config)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def convert_keys(hash)
|
|
113
|
+
hash.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def default_configuration_paths
|
|
117
|
+
['.solr_wrapper', '~/.solr_wrapper']
|
|
102
118
|
end
|
|
103
119
|
end
|
|
104
120
|
end
|
|
@@ -1,17 +1,23 @@
|
|
|
1
|
+
require 'ruby-progressbar'
|
|
2
|
+
|
|
1
3
|
module SolrWrapper
|
|
2
4
|
class Downloader
|
|
3
5
|
def self.fetch_with_progressbar(url, output)
|
|
4
|
-
pbar =
|
|
5
|
-
open(url, content_length_proc:
|
|
6
|
-
if t && 0 < t
|
|
7
|
-
pbar.total = t
|
|
8
|
-
end
|
|
9
|
-
end,
|
|
10
|
-
progress_proc: lambda do|s|
|
|
11
|
-
pbar.progress = s
|
|
12
|
-
end) do |io|
|
|
6
|
+
pbar = SafeProgressBar.new(title: File.basename(url), total: nil, format: '%t: |%B| %p%% (%e )')
|
|
7
|
+
open(url, content_length_proc: ->(bytes) { pbar.total = bytes }, progress_proc: ->(bytes) { pbar.progress = bytes }) do |io|
|
|
13
8
|
IO.copy_stream(io, output)
|
|
14
9
|
end
|
|
15
10
|
end
|
|
11
|
+
|
|
12
|
+
class SafeProgressBar < ProgressBar::Base
|
|
13
|
+
def progress=(new_progress)
|
|
14
|
+
self.total = new_progress if total <= new_progress
|
|
15
|
+
super
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def total=(new_total)
|
|
19
|
+
super if new_total && new_total > 0
|
|
20
|
+
end
|
|
21
|
+
end
|
|
16
22
|
end
|
|
17
23
|
end
|
|
@@ -2,7 +2,6 @@ require 'digest'
|
|
|
2
2
|
require 'fileutils'
|
|
3
3
|
require 'json'
|
|
4
4
|
require 'open-uri'
|
|
5
|
-
require 'ruby-progressbar'
|
|
6
5
|
require 'securerandom'
|
|
7
6
|
require 'socket'
|
|
8
7
|
require 'stringio'
|
|
@@ -146,6 +145,7 @@ module SolrWrapper
|
|
|
146
145
|
# @option options [String] :name
|
|
147
146
|
# @option options [String] :dir
|
|
148
147
|
def with_collection(options = {})
|
|
148
|
+
options = config.collection_options.merge(options)
|
|
149
149
|
return yield if options.empty?
|
|
150
150
|
|
|
151
151
|
name = create(options)
|
data/lib/solr_wrapper/version.rb
CHANGED
data/lib/solr_wrapper.rb
CHANGED
|
@@ -21,4 +21,24 @@ describe SolrWrapper::Configuration do
|
|
|
21
21
|
it { is_expected.to eq '8888' }
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
|
+
|
|
25
|
+
describe "#read_config" do
|
|
26
|
+
before do
|
|
27
|
+
allow(config).to receive(:default_configuration_paths).and_return([])
|
|
28
|
+
end
|
|
29
|
+
let(:options) { { config: 'spec/fixtures/sample_config.yml' } }
|
|
30
|
+
it "uses values from the config file" do
|
|
31
|
+
expect(config.port).to eq '9999'
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe "#collection_options" do
|
|
36
|
+
before do
|
|
37
|
+
allow(config).to receive(:default_configuration_paths).and_return([])
|
|
38
|
+
end
|
|
39
|
+
let(:options) { { config: 'spec/fixtures/sample_config.yml' } }
|
|
40
|
+
it "uses values from the config file" do
|
|
41
|
+
expect(config.collection_options).to eq(name: 'project-development', dir: 'solr/config/')
|
|
42
|
+
end
|
|
43
|
+
end
|
|
24
44
|
end
|
|
@@ -6,17 +6,32 @@ describe SolrWrapper::Instance do
|
|
|
6
6
|
let(:client) { SimpleSolrClient::Client.new(subject.url) }
|
|
7
7
|
|
|
8
8
|
describe "#with_collection" do
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
context "without a name" do
|
|
10
|
+
it "creates a new anonymous collection" do
|
|
11
|
+
subject.wrap do |solr|
|
|
12
|
+
solr.with_collection(dir: File.join(FIXTURES_DIR, "basic_configs")) do |collection_name|
|
|
13
|
+
core = client.core(collection_name)
|
|
14
|
+
unless defined? JRUBY_VERSION
|
|
15
|
+
expect(core.schema.field('id').name).to eq 'id'
|
|
16
|
+
expect(core.schema.field('id').stored).to eq true
|
|
17
|
+
end
|
|
16
18
|
end
|
|
17
19
|
end
|
|
18
20
|
end
|
|
19
21
|
end
|
|
22
|
+
context "with a config file" do
|
|
23
|
+
before do
|
|
24
|
+
allow(solr_instance.config).to receive(:collection_options)
|
|
25
|
+
.and_return(name: 'project-development', dir: 'solr/config/')
|
|
26
|
+
allow(solr_instance).to receive(:delete)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "creates a new collection with options from the config" do
|
|
30
|
+
expect(solr_instance).to receive(:create).with(
|
|
31
|
+
hash_including(name: "project-development", dir: anything))
|
|
32
|
+
solr_instance.with_collection(dir: File.join(FIXTURES_DIR, "basic_configs")) {}
|
|
33
|
+
end
|
|
34
|
+
end
|
|
20
35
|
end
|
|
21
36
|
|
|
22
37
|
describe 'exec' do
|
|
@@ -58,7 +73,7 @@ describe SolrWrapper::Instance do
|
|
|
58
73
|
|
|
59
74
|
describe "#version" do
|
|
60
75
|
subject { solr_instance.version }
|
|
61
|
-
it { is_expected.to eq '
|
|
76
|
+
it { is_expected.to eq '6.0.0' }
|
|
62
77
|
end
|
|
63
78
|
|
|
64
79
|
describe "#md5" do
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: solr_wrapper
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.8.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-04-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rubyzip
|
|
@@ -146,6 +146,7 @@ files:
|
|
|
146
146
|
- spec/fixtures/basic_configs/solrconfig.xml
|
|
147
147
|
- spec/fixtures/basic_configs/stopwords.txt
|
|
148
148
|
- spec/fixtures/basic_configs/synonyms.txt
|
|
149
|
+
- spec/fixtures/sample_config.yml
|
|
149
150
|
- spec/lib/solr_wrapper/configuration_spec.rb
|
|
150
151
|
- spec/lib/solr_wrapper/instance_spec.rb
|
|
151
152
|
- spec/lib/solr_wrapper_spec.rb
|
|
@@ -170,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
170
171
|
version: '0'
|
|
171
172
|
requirements: []
|
|
172
173
|
rubyforge_project:
|
|
173
|
-
rubygems_version: 2.5.1
|
|
174
|
+
rubygems_version: 2.4.5.1
|
|
174
175
|
signing_key:
|
|
175
176
|
specification_version: 4
|
|
176
177
|
summary: Solr 5 service wrapper
|
|
@@ -183,8 +184,8 @@ test_files:
|
|
|
183
184
|
- spec/fixtures/basic_configs/solrconfig.xml
|
|
184
185
|
- spec/fixtures/basic_configs/stopwords.txt
|
|
185
186
|
- spec/fixtures/basic_configs/synonyms.txt
|
|
187
|
+
- spec/fixtures/sample_config.yml
|
|
186
188
|
- spec/lib/solr_wrapper/configuration_spec.rb
|
|
187
189
|
- spec/lib/solr_wrapper/instance_spec.rb
|
|
188
190
|
- spec/lib/solr_wrapper_spec.rb
|
|
189
191
|
- spec/spec_helper.rb
|
|
190
|
-
has_rdoc:
|