rsolr 0.12.0 → 2.6.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.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ruby.yml +29 -0
  3. data/.gitignore +13 -0
  4. data/.rspec +2 -0
  5. data/CHANGES.txt +63 -260
  6. data/Gemfile +13 -0
  7. data/README.rdoc +177 -63
  8. data/Rakefile +19 -0
  9. data/lib/rsolr/char.rb +6 -0
  10. data/lib/rsolr/client.rb +344 -86
  11. data/lib/rsolr/document.rb +66 -0
  12. data/lib/rsolr/error.rb +182 -0
  13. data/lib/rsolr/field.rb +87 -0
  14. data/lib/rsolr/generator.rb +5 -0
  15. data/lib/rsolr/json.rb +60 -0
  16. data/lib/rsolr/response.rb +95 -0
  17. data/lib/rsolr/uri.rb +25 -0
  18. data/lib/rsolr/version.rb +7 -0
  19. data/lib/rsolr/xml.rb +150 -0
  20. data/lib/rsolr.rb +47 -35
  21. data/rsolr.gemspec +44 -31
  22. data/spec/api/client_spec.rb +423 -0
  23. data/spec/api/document_spec.rb +48 -0
  24. data/spec/api/error_spec.rb +158 -0
  25. data/spec/api/json_spec.rb +248 -0
  26. data/spec/api/pagination_spec.rb +31 -0
  27. data/spec/api/rsolr_spec.rb +31 -0
  28. data/spec/api/uri_spec.rb +37 -0
  29. data/spec/api/xml_spec.rb +255 -0
  30. data/spec/fixtures/basic_configs/_rest_managed.json +1 -0
  31. data/spec/fixtures/basic_configs/currency.xml +67 -0
  32. data/spec/fixtures/basic_configs/lang/stopwords_en.txt +54 -0
  33. data/spec/fixtures/basic_configs/protwords.txt +21 -0
  34. data/spec/fixtures/basic_configs/schema.xml +530 -0
  35. data/spec/fixtures/basic_configs/solrconfig.xml +572 -0
  36. data/spec/fixtures/basic_configs/stopwords.txt +14 -0
  37. data/spec/fixtures/basic_configs/synonyms.txt +29 -0
  38. data/spec/integration/solr5_spec.rb +38 -0
  39. data/spec/lib/rsolr/client_spec.rb +19 -0
  40. data/spec/spec_helper.rb +94 -0
  41. metadata +228 -54
  42. data/lib/rsolr/connection/net_http.rb +0 -48
  43. data/lib/rsolr/connection/requestable.rb +0 -43
  44. data/lib/rsolr/connection/utils.rb +0 -73
  45. data/lib/rsolr/connection.rb +0 -9
  46. data/lib/rsolr/message/document.rb +0 -48
  47. data/lib/rsolr/message/field.rb +0 -20
  48. data/lib/rsolr/message/generator.rb +0 -89
  49. data/lib/rsolr/message.rb +0 -8
@@ -0,0 +1,255 @@
1
+ require 'spec_helper'
2
+ require 'builder'
3
+ require 'nokogiri'
4
+
5
+ RSpec.describe RSolr::Xml do
6
+ let(:generator){ RSolr::Xml::Generator.new }
7
+
8
+ builder_engines = {
9
+ :builder => { :val => false, :class => Builder::XmlMarkup, :engine => Builder::XmlMarkup.new(:indent => 0, :margin => 0, :encoding => 'UTF-8') },
10
+ :nokogiri => { :val => true, :class => Nokogiri::XML::Builder, :engine => Nokogiri::XML::Builder.new }
11
+ }
12
+
13
+ [:builder,:nokogiri].each do |engine_name|
14
+ describe engine_name do
15
+ before :all do
16
+ @engine = builder_engines[engine_name]
17
+ @old_ng_setting = RSolr::Xml::Generator.use_nokogiri
18
+ RSolr::Xml::Generator.use_nokogiri = @engine[:val]
19
+ end
20
+
21
+ after :all do
22
+ RSolr::Xml::Generator.use_nokogiri = @old_ng_setting
23
+ end
24
+
25
+ before :each do
26
+ builder_engines.each_pair do |name,spec|
27
+ expect(spec[:class]).not_to receive(:new) unless name == engine_name
28
+ end
29
+ end
30
+
31
+ context :xml_engine do
32
+ it "should use #{engine_name}" do
33
+ expect(@engine[:class]).to receive(:new).and_return(@engine[:engine])
34
+ generator.send(:commit)
35
+ end
36
+ end
37
+
38
+ # call all of the simple methods...
39
+ # make sure the xml string is valid
40
+ # ensure the class is actually Solr::XML
41
+ [:optimize, :rollback, :commit].each do |meth|
42
+ it "#{meth} should generator xml" do
43
+ result = generator.send(meth)
44
+ expect(result).to eq("<?xml version=\"1.0\" encoding=\"UTF-8\"?><#{meth}/>")
45
+ end
46
+ end
47
+
48
+ context :add do
49
+
50
+ it 'should yield a Message::Document object when #add is called with a block' do
51
+ documents = [{:id=>1, :name=>'sam', :cat=>['cat 1', 'cat 2']}]
52
+ add_attrs = {:boost=>200.00}
53
+ result = generator.add(documents, add_attrs) do |doc|
54
+ doc.field_by_name(:name).attrs[:boost] = 10
55
+ end
56
+ expect(result).to match(%r(name="cat">cat 1</field>))
57
+ expect(result).to match(%r(name="cat">cat 2</field>))
58
+ expect(result).to match(%r(<add boost="200.0">))
59
+ expect(result).to match(%r(boost="10"))
60
+ expect(result).to match(%r(<field name="id">1</field>))
61
+ end
62
+
63
+ it 'should work for values that yield enumerators' do
64
+ documents = [{id: 1, cat: ['cat 1', 'cat 2'].to_enum}]
65
+ result = generator.add(documents)
66
+
67
+ expect(result).to match(%r(name="cat">cat 1</field>))
68
+ expect(result).to match(%r(name="cat">cat 2</field>))
69
+ end
70
+
71
+ # add a single hash ("doc")
72
+ it 'should create an add from a hash' do
73
+ data = {
74
+ :id=>1,
75
+ :name=>'matt'
76
+ }
77
+ result = generator.add(data)
78
+ expect(result).to match(/<field name="name">matt<\/field>/)
79
+ expect(result).to match(/<field name="id">1<\/field>/)
80
+ end
81
+
82
+ # add a single hash ("doc")
83
+ it 'should create an add from a hash formatted for atomic updates' do
84
+ data = {
85
+ :id=>1,
86
+ :name=> { set: 'matt' }
87
+ }
88
+ result = generator.add(data)
89
+ expect(result).to match(/<field name="name" update="set">matt<\/field>/)
90
+ expect(result).to match(/<field name="id">1<\/field>/)
91
+ end
92
+ it 'should remove a field from a hash formatted for atomic updates' do
93
+ data = {
94
+ :id => 1,
95
+ :name => nil
96
+ }
97
+ result = generator.add(data)
98
+ expect(result).to match(%r{<field name="name" null="true"})
99
+ expect(result).to match(/<field name="id">1<\/field>/)
100
+ end
101
+
102
+ # add an array of hashes
103
+ it 'should create many adds from an array of hashes' do
104
+ data = [
105
+ {
106
+ :id=>1,
107
+ :name=>'matt'
108
+ },
109
+ {
110
+ :id=>2,
111
+ :name=>'sam'
112
+ }
113
+ ]
114
+ message = generator.add(data)
115
+ expect(message).to match %r{<field name="name">matt</field>}
116
+ expect(message).to match %r{<field name="name">sam</field>}
117
+ end
118
+
119
+ # multiValue field support test, thanks to Fouad Mardini!
120
+ it 'should create multiple fields from array values' do
121
+ data = {
122
+ :id => 1,
123
+ :name => ['matt1', 'matt2']
124
+ }
125
+ result = generator.add(data)
126
+ expect(result).to match(/<field name="name">matt1<\/field>/)
127
+ expect(result).to match(/<field name="name">matt2<\/field>/)
128
+ end
129
+
130
+ it 'should allow for objects which can be casted to an array' do
131
+ name = double("name", to_ary: ['matt1', 'matt2'])
132
+ data = {
133
+ :id => 1,
134
+ :name => name
135
+ }
136
+ result = generator.add(data)
137
+ expect(result).to match(/<field name="name">matt1<\/field>/)
138
+ expect(result).to match(/<field name="name">matt2<\/field>/)
139
+ end
140
+
141
+ it 'should create an add from a single Message::Document' do
142
+ document = RSolr::Document.new
143
+ document.add_field('id', 1)
144
+ document.add_field('name', 'matt', :boost => 2.0)
145
+ result = generator.add(document)
146
+ expect(result).to match(Regexp.escape('<?xml version="1.0" encoding="UTF-8"?>'))
147
+ expect(result).to match(/<field name="id">1<\/field>/)
148
+ expect(result).to match Regexp.escape('boost="2.0"')
149
+ expect(result).to match Regexp.escape('name="name"')
150
+ expect(result).to match Regexp.escape('matt</field>')
151
+ end
152
+
153
+ it 'should create adds from multiple Message::Documents' do
154
+ documents = (1..2).map do |i|
155
+ doc = RSolr::Document.new
156
+ doc.add_field('id', i)
157
+ doc.add_field('name', "matt#{i}")
158
+ doc
159
+ end
160
+ result = generator.add(documents)
161
+ expect(result).to match(/<field name="name">matt1<\/field>/)
162
+ expect(result).to match(/<field name="name">matt2<\/field>/)
163
+ end
164
+
165
+ it 'supports nested child documents' do
166
+ data = {
167
+ :_childDocuments_ => [
168
+ {
169
+ :id => 1
170
+ },
171
+ {
172
+ :id => 2
173
+ }
174
+ ]
175
+ }
176
+
177
+ result = generator.add(data)
178
+ expect(result).to match(%r{<add><doc><doc>})
179
+ expect(result).to match(%r{<doc><field name="id">1</field></doc>})
180
+ expect(result).to match(%r{<doc><field name="id">2</field></doc>})
181
+ end
182
+ end
183
+
184
+ context :delete_by_id do
185
+
186
+ it 'should create a doc id delete' do
187
+ expect(generator.delete_by_id(10)).to eq("<?xml version=\"1.0\" encoding=\"UTF-8\"?><delete><id>10</id></delete>")
188
+ end
189
+
190
+ it 'should create many doc id deletes' do
191
+ expect(generator.delete_by_id([1, 2, 3])).to eq("<?xml version=\"1.0\" encoding=\"UTF-8\"?><delete><id>1</id><id>2</id><id>3</id></delete>")
192
+ end
193
+
194
+ end
195
+
196
+ context :delete_by_query do
197
+ it 'should create a query delete' do
198
+ expect(generator.delete_by_query('status:"LOST"')).to eq("<?xml version=\"1.0\" encoding=\"UTF-8\"?><delete><query>status:\"LOST\"</query></delete>")
199
+ end
200
+
201
+ it 'should create many query deletes' do
202
+ expect(generator.delete_by_query(['status:"LOST"', 'quantity:0'])).to eq("<?xml version=\"1.0\" encoding=\"UTF-8\"?><delete><query>status:\"LOST\"</query><query>quantity:0</query></delete>")
203
+ end
204
+ end
205
+
206
+ end
207
+ end
208
+
209
+ context :formatting do
210
+ it 'should format date objects into ISO 8601' do
211
+ data = {
212
+ dt: Date.new(1992, 03, 15)
213
+ }
214
+ result = generator.add(data)
215
+ expect(result).to match(/<field name="dt">1992-03-15T00:00:00Z<\/field>/)
216
+ end
217
+
218
+ it 'should format time objects into ISO 8601' do
219
+ data = {
220
+ dt: Time.new(1992, 03, 15, 16, 23, 55, 3600)
221
+ }
222
+ result = generator.add(data)
223
+ expect(result).to match(/<field name="dt">1992-03-15T15:23:55Z<\/field>/)
224
+ end
225
+
226
+ it 'should format datetime objects into ISO 8601' do
227
+ data = {
228
+ dt: DateTime.new(1992, 03, 15, 16, 23, 55, '+1')
229
+ }
230
+ result = generator.add(data)
231
+ expect(result).to match(/<field name="dt">1992-03-15T15:23:55Z<\/field>/)
232
+ end
233
+
234
+ it 'passes through other values' do
235
+ data = {
236
+ whatever: 'some string'
237
+ }
238
+
239
+ result = generator.add(data)
240
+ expect(result).to match(/<field name="whatever">some string<\/field>/)
241
+ end
242
+
243
+ # rails monkey-patches String to add a #to_time casting..
244
+ context 'with rails monkey patching' do
245
+ it 'passes through string values' do
246
+ data = {
247
+ whatever: double(to_s: 'some string', to_time: nil)
248
+ }
249
+
250
+ result = generator.add(data)
251
+ expect(result).to match(/<field name="whatever">some string<\/field>/)
252
+ end
253
+ end
254
+ end
255
+ 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
@@ -0,0 +1,21 @@
1
+ # The ASF licenses this file to You under the Apache License, Version 2.0
2
+ # (the "License"); you may not use this file except in compliance with
3
+ # the License. You may obtain a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS,
9
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ # See the License for the specific language governing permissions and
11
+ # limitations under the License.
12
+
13
+ #-----------------------------------------------------------------------
14
+ # Use a protected word file to protect against the stemmer reducing two
15
+ # unrelated words to the same base word.
16
+
17
+ # Some non-words that normally won't be encountered,
18
+ # just to test that they won't be stemmed.
19
+ dontstems
20
+ zwhacky
21
+