solr_wrapper 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2980ce0da6b13f768917b7a81ebeb45dfd2a4ff6
4
+ data.tar.gz: b8f4d793718df779050a5c571016b326cd8e3de3
5
+ SHA512:
6
+ metadata.gz: 635757846c0b44d01d92993837555a38661c97638b745cc83d55be0fd59f098c09ad05fa7e316afcfe0dd8c49199d43dc22ad435994392bb5f67d84a87cf251b
7
+ data.tar.gz: 84d932af417c6823d9666361ab2044dad3112555121d5b7df4bca6ec72e32408265167f67fbe838e76ac8f42039e19c483ae40e5e6b4c9b39fa2c4aab4f87554
data/.gitignore ADDED
@@ -0,0 +1,35 @@
1
+ Gemfile.lock
2
+ *.gem
3
+ *.rbc
4
+ /.config
5
+ /coverage/
6
+ /InstalledFiles
7
+ /pkg/
8
+ /spec/reports/
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalisation:
25
+ /.bundle/
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in solr_wrapper.gemspec
4
+ gemspec
5
+
6
+ gem 'byebug'
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Chris Beer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1 @@
1
+ # solrwrapper
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,16 @@
1
+ require 'solr_wrapper/version'
2
+ require 'solr_wrapper/instance'
3
+
4
+ module SolrWrapper
5
+ def self.default_solr_version
6
+ "5.0.0"
7
+ end
8
+
9
+ def self.default_instance options
10
+ @default_instance ||= SolrWrapper::Instance.new options
11
+ end
12
+
13
+ def self.wrap options = {}, &block
14
+ default_instance(options).wrap &block
15
+ end
16
+ end
@@ -0,0 +1,214 @@
1
+ require 'digest'
2
+ require 'fileutils'
3
+ require 'open-uri'
4
+ require 'progressbar'
5
+ require 'securerandom'
6
+ require 'tmpdir'
7
+ require 'zip'
8
+
9
+ module SolrWrapper
10
+ class Instance
11
+ attr_reader :options
12
+
13
+ def initialize options = {}
14
+ @options = options
15
+ end
16
+
17
+ def wrap &block
18
+ start
19
+ yield self
20
+ ensure
21
+ stop
22
+ end
23
+
24
+ def start
25
+ extract
26
+ IO.popen([solr_binary, "start", "-p", port, err: [:child, :out]]) do |io|
27
+ if verbose?
28
+ IO.copy_stream(io,$stderr)
29
+ end
30
+ end if managed?
31
+ started!
32
+ end
33
+
34
+ def stop
35
+ return unless started?
36
+
37
+ IO.popen([solr_binary, "stop", "-p", port, err: [:child, :out]]) do |io|
38
+ if verbose?
39
+ IO.copy_stream(io,$stderr)
40
+ end
41
+ end if managed?
42
+ end
43
+
44
+ def started?
45
+ !!@started
46
+ end
47
+
48
+ def extract
49
+ zip_path = download
50
+
51
+ begin
52
+ Zip::File.open(zip_path) do |zip_file|
53
+ # Handle entries one by one
54
+ zip_file.each do |entry|
55
+ dest_file = File.join(tmp_save_dir,entry.name)
56
+ FileUtils.remove_entry(dest_file,true)
57
+ entry.extract(dest_file)
58
+ end
59
+ end
60
+
61
+ rescue Exception => e
62
+ abort "Unable to unzip #{zip_path} into #{tmp_save_dir}: #{e.message}"
63
+ end
64
+
65
+ begin
66
+ FileUtils.remove_dir(solr_dir,true)
67
+ FileUtils.cp_r File.join(tmp_save_dir, File.basename(default_url, ".zip")), solr_dir
68
+ FileUtils.chmod 0755, solr_binary
69
+ rescue Exception => e
70
+ abort "Unable to copy #{tmp_save_dir} to #{solr_dir}: #{e.message}"
71
+ end
72
+
73
+ solr_dir
74
+ ensure
75
+ FileUtils.remove_entry tmp_save_dir
76
+ end
77
+
78
+ def download
79
+ unless File.exists? download_path and md5sum(download_path) == expected_md5sum
80
+ pbar = ProgressBar.new("solr", nil)
81
+ open(url, content_length_proc: lambda {|t|
82
+ if t && 0 < t
83
+ pbar.total = t
84
+ pbar.file_transfer_mode
85
+ end
86
+ },
87
+ progress_proc: lambda {|s|
88
+ pbar.set s if pbar
89
+ }) do |io|
90
+ IO.copy_stream(io,download_path)
91
+ end
92
+
93
+ unless md5sum(download_path) == expected_md5sum
94
+ raise "MD5 mismatch" unless options[:ignore_md5sum]
95
+ end
96
+ end
97
+
98
+ download_path
99
+ end
100
+
101
+ def port
102
+ options.fetch(:port, "8983")
103
+ end
104
+
105
+ def create options = {}
106
+ options[:name] ||= SecureRandom.hex
107
+
108
+ IO.popen([solr_binary, "create", "-c", options[:name], "-d", options[:dir], "-p", port, err: [:child, :out]]) do |io|
109
+ if verbose?
110
+ IO.copy_stream(io,$stderr)
111
+ end
112
+ end
113
+
114
+ options[:name]
115
+ end
116
+
117
+ def delete name, options = {}
118
+ IO.popen([solr_binary, "delete", "-c", name, "-p", port, err: [:child, :out]]) do |io|
119
+ if verbose?
120
+ IO.copy_stream(io,$stderr)
121
+ end
122
+ end
123
+ end
124
+
125
+ def with_collection options = {}
126
+ name = create(options)
127
+ begin
128
+ yield name
129
+ ensure
130
+ delete name
131
+ end
132
+ end
133
+
134
+ private
135
+ def expected_md5sum
136
+ @md5sum ||= options.fetch(:md5sum, open(md5file).read.split(" ").first)
137
+ end
138
+
139
+ def md5sum file
140
+ Digest::MD5.file(file).hexdigest
141
+ end
142
+
143
+ def md5file
144
+ unless File.exists? md5sum_path
145
+ pbar = ProgressBar.new("md5", nil)
146
+ open(md5url, content_length_proc: lambda {|t|
147
+ if t && 0 < t
148
+ pbar.total = t
149
+ pbar.file_transfer_mode
150
+ end
151
+ },
152
+ progress_proc: lambda {|s|
153
+ pbar.set s if pbar
154
+ }) do |io|
155
+ IO.copy_stream(io, md5sum_path)
156
+ end
157
+ end
158
+
159
+ md5sum_path
160
+ end
161
+
162
+ def md5url
163
+ "http://www.us.apache.org/dist/lucene/solr/#{version}/solr-#{version}.zip.md5"
164
+ end
165
+
166
+ def md5sum_path
167
+ File.join(Dir.tmpdir, File.basename(md5url))
168
+ end
169
+
170
+ def url
171
+ @download_url ||= options.fetch(:url, default_url)
172
+ end
173
+
174
+ def default_url
175
+ "http://mirrors.ibiblio.org/apache/lucene/solr/#{version}/solr-#{version}.zip"
176
+ end
177
+
178
+ def version
179
+ @version ||= options.fetch(:version, SolrWrapper.default_solr_version)
180
+ end
181
+
182
+ def download_path
183
+ @download_path ||= options.fetch(:download_path, default_download_path)
184
+ end
185
+
186
+ def default_download_path
187
+ File.join(Dir.tmpdir, File.basename(default_url))
188
+ end
189
+
190
+ def solr_dir
191
+ @solr_dir ||= options.fetch(:instance_dir, File.join(Dir.tmpdir, File.basename(default_url, ".zip")))
192
+ end
193
+
194
+ def tmp_save_dir
195
+ @tmp_save_dir ||= Dir.mktmpdir
196
+ end
197
+
198
+ def solr_binary
199
+ File.join(solr_dir, "bin", "solr")
200
+ end
201
+
202
+ def started! status = true
203
+ @started = status
204
+ end
205
+
206
+ def verbose?
207
+ !!options.fetch(:verbose, false)
208
+ end
209
+
210
+ def managed?
211
+ !!options.fetch(:managed, true)
212
+ end
213
+ end
214
+ end
@@ -0,0 +1,3 @@
1
+ module SolrWrapper
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'solr_wrapper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "solr_wrapper"
8
+ spec.version = SolrWrapper::VERSION
9
+ spec.authors = ["Chris Beer"]
10
+ spec.email = ["chris@cbeer.info"]
11
+ spec.summary = %q{Solr 5 service wrapper}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "rubyzip"
21
+ spec.add_dependency "progressbar"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "simple_solr_client"
28
+ end
@@ -0,0 +1 @@
1
+ {"initArgs":{},"managedList":[]}
@@ -0,0 +1,67 @@
1
+ <?xml version="1.0" ?>
2
+ <!--
3
+ Licensed to the Apache Software Foundation (ASF) under one or more
4
+ contributor license agreements. See the NOTICE file distributed with
5
+ this work for additional information regarding copyright ownership.
6
+ The ASF licenses this file to You under the Apache License, Version 2.0
7
+ (the "License"); you may not use this file except in compliance with
8
+ the License. You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing, software
13
+ distributed under the License is distributed on an "AS IS" BASIS,
14
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ See the License for the specific language governing permissions and
16
+ limitations under the License.
17
+ -->
18
+
19
+ <!-- Example exchange rates file for CurrencyField type named "currency" in example schema -->
20
+
21
+ <currencyConfig version="1.0">
22
+ <rates>
23
+ <!-- Updated from http://www.exchangerate.com/ at 2011-09-27 -->
24
+ <rate from="USD" to="ARS" rate="4.333871" comment="ARGENTINA Peso" />
25
+ <rate from="USD" to="AUD" rate="1.025768" comment="AUSTRALIA Dollar" />
26
+ <rate from="USD" to="EUR" rate="0.743676" comment="European Euro" />
27
+ <rate from="USD" to="BRL" rate="1.881093" comment="BRAZIL Real" />
28
+ <rate from="USD" to="CAD" rate="1.030815" comment="CANADA Dollar" />
29
+ <rate from="USD" to="CLP" rate="519.0996" comment="CHILE Peso" />
30
+ <rate from="USD" to="CNY" rate="6.387310" comment="CHINA Yuan" />
31
+ <rate from="USD" to="CZK" rate="18.47134" comment="CZECH REP. Koruna" />
32
+ <rate from="USD" to="DKK" rate="5.515436" comment="DENMARK Krone" />
33
+ <rate from="USD" to="HKD" rate="7.801922" comment="HONG KONG Dollar" />
34
+ <rate from="USD" to="HUF" rate="215.6169" comment="HUNGARY Forint" />
35
+ <rate from="USD" to="ISK" rate="118.1280" comment="ICELAND Krona" />
36
+ <rate from="USD" to="INR" rate="49.49088" comment="INDIA Rupee" />
37
+ <rate from="USD" to="XDR" rate="0.641358" comment="INTNL MON. FUND SDR" />
38
+ <rate from="USD" to="ILS" rate="3.709739" comment="ISRAEL Sheqel" />
39
+ <rate from="USD" to="JPY" rate="76.32419" comment="JAPAN Yen" />
40
+ <rate from="USD" to="KRW" rate="1169.173" comment="KOREA (SOUTH) Won" />
41
+ <rate from="USD" to="KWD" rate="0.275142" comment="KUWAIT Dinar" />
42
+ <rate from="USD" to="MXN" rate="13.85895" comment="MEXICO Peso" />
43
+ <rate from="USD" to="NZD" rate="1.285159" comment="NEW ZEALAND Dollar" />
44
+ <rate from="USD" to="NOK" rate="5.859035" comment="NORWAY Krone" />
45
+ <rate from="USD" to="PKR" rate="87.57007" comment="PAKISTAN Rupee" />
46
+ <rate from="USD" to="PEN" rate="2.730683" comment="PERU Sol" />
47
+ <rate from="USD" to="PHP" rate="43.62039" comment="PHILIPPINES Peso" />
48
+ <rate from="USD" to="PLN" rate="3.310139" comment="POLAND Zloty" />
49
+ <rate from="USD" to="RON" rate="3.100932" comment="ROMANIA Leu" />
50
+ <rate from="USD" to="RUB" rate="32.14663" comment="RUSSIA Ruble" />
51
+ <rate from="USD" to="SAR" rate="3.750465" comment="SAUDI ARABIA Riyal" />
52
+ <rate from="USD" to="SGD" rate="1.299352" comment="SINGAPORE Dollar" />
53
+ <rate from="USD" to="ZAR" rate="8.329761" comment="SOUTH AFRICA Rand" />
54
+ <rate from="USD" to="SEK" rate="6.883442" comment="SWEDEN Krona" />
55
+ <rate from="USD" to="CHF" rate="0.906035" comment="SWITZERLAND Franc" />
56
+ <rate from="USD" to="TWD" rate="30.40283" comment="TAIWAN Dollar" />
57
+ <rate from="USD" to="THB" rate="30.89487" comment="THAILAND Baht" />
58
+ <rate from="USD" to="AED" rate="3.672955" comment="U.A.E. Dirham" />
59
+ <rate from="USD" to="UAH" rate="7.988582" comment="UKRAINE Hryvnia" />
60
+ <rate from="USD" to="GBP" rate="0.647910" comment="UNITED KINGDOM Pound" />
61
+
62
+ <!-- Cross-rates for some common currencies -->
63
+ <rate from="EUR" to="GBP" rate="0.869914" />
64
+ <rate from="EUR" to="NOK" rate="7.800095" />
65
+ <rate from="GBP" to="NOK" rate="8.966508" />
66
+ </rates>
67
+ </currencyConfig>
@@ -0,0 +1,54 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one or more
2
+ # contributor license agreements. See the NOTICE file distributed with
3
+ # this work for additional information regarding copyright ownership.
4
+ # The ASF licenses this file to You under the Apache License, Version 2.0
5
+ # (the "License"); you may not use this file except in compliance with
6
+ # the License. You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ # a couple of test stopwords to test that the words are really being
17
+ # configured from this file:
18
+ stopworda
19
+ stopwordb
20
+
21
+ # Standard english stop words taken from Lucene's StopAnalyzer
22
+ a
23
+ an
24
+ and
25
+ are
26
+ as
27
+ at
28
+ be
29
+ but
30
+ by
31
+ for
32
+ if
33
+ in
34
+ into
35
+ is
36
+ it
37
+ no
38
+ not
39
+ of
40
+ on
41
+ or
42
+ such
43
+ that
44
+ the
45
+ their
46
+ then
47
+ there
48
+ these
49
+ they
50
+ this
51
+ to
52
+ was
53
+ will
54
+ with