zigexn_solr-ruby 0.0.1
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 +7 -0
- data/LICENSE.txt +201 -0
- data/README.md +41 -0
- data/lib/solr/connection.rb +179 -0
- data/lib/solr/document.rb +73 -0
- data/lib/solr/exception.rb +13 -0
- data/lib/solr/field.rb +39 -0
- data/lib/solr/importer/array_mapper.rb +26 -0
- data/lib/solr/importer/delimited_file_source.rb +38 -0
- data/lib/solr/importer/hpricot_mapper.rb +27 -0
- data/lib/solr/importer/mapper.rb +51 -0
- data/lib/solr/importer/solr_source.rb +43 -0
- data/lib/solr/importer/xpath_mapper.rb +35 -0
- data/lib/solr/importer.rb +19 -0
- data/lib/solr/indexer.rb +52 -0
- data/lib/solr/request/add_document.rb +63 -0
- data/lib/solr/request/base.rb +36 -0
- data/lib/solr/request/commit.rb +30 -0
- data/lib/solr/request/delete.rb +50 -0
- data/lib/solr/request/dismax.rb +46 -0
- data/lib/solr/request/index_info.rb +22 -0
- data/lib/solr/request/modify_document.rb +51 -0
- data/lib/solr/request/optimize.rb +21 -0
- data/lib/solr/request/ping.rb +36 -0
- data/lib/solr/request/select.rb +56 -0
- data/lib/solr/request/spellcheck.rb +30 -0
- data/lib/solr/request/standard.rb +376 -0
- data/lib/solr/request/update.rb +23 -0
- data/lib/solr/request.rb +26 -0
- data/lib/solr/response/add_document.rb +17 -0
- data/lib/solr/response/base.rb +42 -0
- data/lib/solr/response/commit.rb +17 -0
- data/lib/solr/response/delete.rb +13 -0
- data/lib/solr/response/dismax.rb +20 -0
- data/lib/solr/response/index_info.rb +26 -0
- data/lib/solr/response/modify_document.rb +17 -0
- data/lib/solr/response/optimize.rb +14 -0
- data/lib/solr/response/ping.rb +28 -0
- data/lib/solr/response/ruby.rb +42 -0
- data/lib/solr/response/select.rb +17 -0
- data/lib/solr/response/spellcheck.rb +20 -0
- data/lib/solr/response/standard.rb +60 -0
- data/lib/solr/response/xml.rb +42 -0
- data/lib/solr/response.rb +27 -0
- data/lib/solr/solrtasks.rb +27 -0
- data/lib/solr/util.rb +32 -0
- data/lib/solr/xml.rb +47 -0
- data/lib/solr.rb +21 -0
- metadata +119 -0
@@ -0,0 +1,376 @@
|
|
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
|
+
class Solr::Request::Standard < Solr::Request::Select
|
14
|
+
|
15
|
+
VALID_PARAMS = [:query, :sort, :default_field, :operator, :start, :rows, :shards,
|
16
|
+
:filter_queries, :field_list, :debug_query, :explain_other, :facets, :highlighting, :mlt]
|
17
|
+
|
18
|
+
def initialize(params)
|
19
|
+
super('standard')
|
20
|
+
|
21
|
+
raise "Invalid parameters: #{(params.keys - VALID_PARAMS).join(',')}" unless
|
22
|
+
(params.keys - VALID_PARAMS).empty?
|
23
|
+
|
24
|
+
raise ":query parameter required" unless params[:query]
|
25
|
+
|
26
|
+
@params = params.dup
|
27
|
+
|
28
|
+
# Validate operator
|
29
|
+
if params[:operator]
|
30
|
+
raise "Only :and/:or operators allowed" unless
|
31
|
+
[:and, :or].include?(params[:operator])
|
32
|
+
|
33
|
+
@params[:operator] = params[:operator].to_s.upcase
|
34
|
+
end
|
35
|
+
|
36
|
+
# Validate start, rows can be transformed to ints
|
37
|
+
@params[:start] = params[:start].to_i if params[:start]
|
38
|
+
@params[:rows] = params[:rows].to_i if params[:rows]
|
39
|
+
|
40
|
+
@params[:field_list] ||= ["*","score"]
|
41
|
+
|
42
|
+
@params[:shards] ||= []
|
43
|
+
end
|
44
|
+
|
45
|
+
def to_hash
|
46
|
+
hash = {}
|
47
|
+
|
48
|
+
# standard request param processing
|
49
|
+
hash[:sort] = @params[:sort].collect do |sort|
|
50
|
+
key = sort.keys[0]
|
51
|
+
"#{key.to_s} #{sort[key] == :descending ? 'desc' : 'asc'}"
|
52
|
+
end.join(',') if @params[:sort]
|
53
|
+
hash[:q] = @params[:query]
|
54
|
+
hash["q.op"] = @params[:operator]
|
55
|
+
hash[:df] = @params[:default_field]
|
56
|
+
|
57
|
+
# common parameter processing
|
58
|
+
hash[:start] = @params[:start]
|
59
|
+
hash[:rows] = @params[:rows]
|
60
|
+
hash[:fq] = @params[:filter_queries]
|
61
|
+
hash[:fl] = @params[:field_list].join(',')
|
62
|
+
hash[:debugQuery] = @params[:debug_query]
|
63
|
+
hash[:explainOther] = @params[:explain_other]
|
64
|
+
hash[:shards] = @params[:shards].join(',') unless @params[:shards].empty?
|
65
|
+
|
66
|
+
# facet parameter processing
|
67
|
+
if @params[:facets]
|
68
|
+
# TODO need validation of all that is under the :facets Hash too
|
69
|
+
hash[:facet] = true
|
70
|
+
hash["facet.field"] = []
|
71
|
+
hash["facet.query"] = @params[:facets][:queries]
|
72
|
+
hash["facet.sort"] = (@params[:facets][:sort] == :count) if @params[:facets][:sort]
|
73
|
+
hash["facet.limit"] = @params[:facets][:limit]
|
74
|
+
hash["facet.missing"] = @params[:facets][:missing]
|
75
|
+
hash["facet.mincount"] = @params[:facets][:mincount]
|
76
|
+
hash["facet.prefix"] = @params[:facets][:prefix]
|
77
|
+
hash["facet.offset"] = @params[:facets][:offset]
|
78
|
+
hash["facet.method"] = @params[:facets][:method] if @params[:facets][:method]
|
79
|
+
if @params[:facets][:fields] # facet fields are optional (could be facet.query only)
|
80
|
+
@params[:facets][:fields].each do |f|
|
81
|
+
if f.kind_of? Hash
|
82
|
+
key = f.keys[0]
|
83
|
+
value = f[key]
|
84
|
+
hash["facet.field"] << key
|
85
|
+
hash["f.#{key}.facet.sort"] = (value[:sort] == :count) if value[:sort]
|
86
|
+
hash["f.#{key}.facet.limit"] = value[:limit]
|
87
|
+
hash["f.#{key}.facet.missing"] = value[:missing]
|
88
|
+
hash["f.#{key}.facet.mincount"] = value[:mincount]
|
89
|
+
hash["f.#{key}.facet.prefix"] = value[:prefix]
|
90
|
+
hash["f.#{key}.facet.offset"] = value[:offset]
|
91
|
+
else
|
92
|
+
hash["facet.field"] << f
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# highlighting parameter processing - http://wiki.apache.org/solr/HighlightingParameters
|
99
|
+
if @params[:highlighting]
|
100
|
+
hash[:hl] = true
|
101
|
+
hash["hl.fl"] = @params[:highlighting][:field_list].join(',') if @params[:highlighting][:field_list]
|
102
|
+
|
103
|
+
snippets = @params[:highlighting][:max_snippets]
|
104
|
+
if snippets
|
105
|
+
if snippets.kind_of? Hash
|
106
|
+
if snippets[:default]
|
107
|
+
hash["hl.snippets"] = snippets[:default]
|
108
|
+
end
|
109
|
+
if snippets[:fields]
|
110
|
+
snippets[:fields].each do |k,v|
|
111
|
+
hash["f.#{k}.hl.snippets"] = v
|
112
|
+
end
|
113
|
+
end
|
114
|
+
else
|
115
|
+
hash["hl.snippets"] = snippets
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
fragsize = @params[:highlighting][:fragment_size]
|
120
|
+
if fragsize
|
121
|
+
if fragsize.kind_of? Hash
|
122
|
+
if fragsize[:default]
|
123
|
+
hash["hl.fragsize"] = fragsize[:default]
|
124
|
+
end
|
125
|
+
if fragsize[:fields]
|
126
|
+
fragsize[:fields].each do |k,v|
|
127
|
+
hash["f.#{k}.hl.fragsize"] = v
|
128
|
+
end
|
129
|
+
end
|
130
|
+
else
|
131
|
+
hash["hl.fragsize"] = fragsize
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
rfm = @params[:highlighting][:require_field_match]
|
136
|
+
if nil != rfm
|
137
|
+
if rfm.kind_of? Hash
|
138
|
+
if nil != rfm[:default]
|
139
|
+
hash["hl.requireFieldMatch"] = rfm[:default]
|
140
|
+
end
|
141
|
+
if rfm[:fields]
|
142
|
+
rfm[:fields].each do |k,v|
|
143
|
+
hash["f.#{k}.hl.requireFieldMatch"] = v
|
144
|
+
end
|
145
|
+
end
|
146
|
+
else
|
147
|
+
hash["hl.requireFieldMatch"] = rfm
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
mac = @params[:highlighting][:max_analyzed_chars]
|
152
|
+
if mac
|
153
|
+
if mac.kind_of? Hash
|
154
|
+
if mac[:default]
|
155
|
+
hash["hl.maxAnalyzedChars"] = mac[:default]
|
156
|
+
end
|
157
|
+
if mac[:fields]
|
158
|
+
mac[:fields].each do |k,v|
|
159
|
+
hash["f.#{k}.hl.maxAnalyzedChars"] = v
|
160
|
+
end
|
161
|
+
end
|
162
|
+
else
|
163
|
+
hash["hl.maxAnalyzedChars"] = mac
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
prefix = @params[:highlighting][:prefix]
|
168
|
+
if prefix
|
169
|
+
if prefix.kind_of? Hash
|
170
|
+
if prefix[:default]
|
171
|
+
hash["hl.simple.pre"] = prefix[:default]
|
172
|
+
end
|
173
|
+
if prefix[:fields]
|
174
|
+
prefix[:fields].each do |k,v|
|
175
|
+
hash["f.#{k}.hl.simple.pre"] = v
|
176
|
+
end
|
177
|
+
end
|
178
|
+
else
|
179
|
+
hash["hl.simple.pre"] = prefix
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
suffix = @params[:highlighting][:suffix]
|
184
|
+
if suffix
|
185
|
+
if suffix.kind_of? Hash
|
186
|
+
if suffix[:default]
|
187
|
+
hash["hl.simple.post"] = suffix[:default]
|
188
|
+
end
|
189
|
+
if suffix[:fields]
|
190
|
+
suffix[:fields].each do |k,v|
|
191
|
+
hash["f.#{k}.hl.simple.post"] = v
|
192
|
+
end
|
193
|
+
end
|
194
|
+
else
|
195
|
+
hash["hl.simple.post"] = suffix
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
formatter = @params[:highlighting][:formatter]
|
200
|
+
if formatter
|
201
|
+
if formatter.kind_of? Hash
|
202
|
+
if formatter[:default]
|
203
|
+
hash["hl.formatter"] = formatter[:default]
|
204
|
+
end
|
205
|
+
if formatter[:fields]
|
206
|
+
formatter[:fields].each do |k,v|
|
207
|
+
hash["f.#{k}.hl.formatter"] = v
|
208
|
+
end
|
209
|
+
end
|
210
|
+
else
|
211
|
+
hash["hl.formatter"] = formatter
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
fragmenter = @params[:highlighting][:fragmenter]
|
216
|
+
if fragmenter
|
217
|
+
if fragmenter.kind_of? Hash
|
218
|
+
if fragmenter[:default]
|
219
|
+
hash["hl.fragmenter"] = fragmenter[:default]
|
220
|
+
end
|
221
|
+
if fragmenter[:fields]
|
222
|
+
fragmenter[:fields].each do |k,v|
|
223
|
+
hash["f.#{k}.hl.fragmenter"] = v
|
224
|
+
end
|
225
|
+
end
|
226
|
+
else
|
227
|
+
hash["hl.fragmenter"] = fragmenter
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
merge_contiguous = @params[:highlighting][:merge_contiguous]
|
232
|
+
if nil != merge_contiguous
|
233
|
+
if merge_contiguous.kind_of? Hash
|
234
|
+
if nil != merge_contiguous[:default]
|
235
|
+
hash["hl.mergeContiguous"] = merge_contiguous[:default]
|
236
|
+
end
|
237
|
+
if merge_contiguous[:fields]
|
238
|
+
merge_contiguous[:fields].each do |k,v|
|
239
|
+
hash["f.#{k}.hl.mergeContiguous"] = v
|
240
|
+
end
|
241
|
+
end
|
242
|
+
else
|
243
|
+
hash["hl.mergeContiguous"] = merge_contiguous
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
increment = @params[:highlighting][:increment]
|
248
|
+
if increment
|
249
|
+
if increment.kind_of? Hash
|
250
|
+
if increment[:default]
|
251
|
+
hash["hl.increment"] = increment[:default]
|
252
|
+
end
|
253
|
+
if increment[:fields]
|
254
|
+
increment[:fields].each do |k,v|
|
255
|
+
hash["f.#{k}.hl.increment"] = v
|
256
|
+
end
|
257
|
+
end
|
258
|
+
else
|
259
|
+
hash["hl.increment"] = increment
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
# support "old style"
|
264
|
+
alternate_fields = @params[:highlighting][:alternate_fields]
|
265
|
+
if alternate_fields
|
266
|
+
alternate_fields.each do |f,v|
|
267
|
+
hash["f.#{f}.hl.alternateField"] = v
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
alternate_field = @params[:highlighting][:alternate_field]
|
272
|
+
if alternate_field
|
273
|
+
if alternate_field.kind_of? Hash
|
274
|
+
if alternate_field[:default]
|
275
|
+
hash["hl.alternateField"] = alternate_field[:default]
|
276
|
+
end
|
277
|
+
if alternate_field[:fields]
|
278
|
+
alternate_field[:fields].each do |k,v|
|
279
|
+
hash["f.#{k}.hl.alternateField"] = v
|
280
|
+
end
|
281
|
+
end
|
282
|
+
else
|
283
|
+
hash["hl.alternateField"] = alternate_field
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
mafl = @params[:highlighting][:max_alternate_field_length]
|
288
|
+
if mafl
|
289
|
+
if mafl.kind_of? Hash
|
290
|
+
if mafl[:default]
|
291
|
+
hash["hl.maxAlternateFieldLength"] = mafl[:default]
|
292
|
+
end
|
293
|
+
if mafl[:fields]
|
294
|
+
mafl[:fields].each do |k,v|
|
295
|
+
hash["f.#{k}.hl.maxAlternateFieldLength"] = v
|
296
|
+
end
|
297
|
+
else
|
298
|
+
# support "old style"
|
299
|
+
mafl.each do |k,v|
|
300
|
+
hash["f.#{k}.hl.maxAlternateFieldLength"] = v
|
301
|
+
end
|
302
|
+
end
|
303
|
+
else
|
304
|
+
hash["hl.maxAlternateFieldLength"] = mafl
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
hash["hl.usePhraseHighlighter"] = @params[:highlighting][:use_phrase_highlighter]
|
309
|
+
|
310
|
+
hash["hl.useFastVectorHighlighter"] = @params[:highlighting][:use_fast_vector_highlighter]
|
311
|
+
|
312
|
+
regex = @params[:highlighting][:regex]
|
313
|
+
if regex
|
314
|
+
if regex[:slop]
|
315
|
+
if regex[:slop].kind_of? Hash
|
316
|
+
if regex[:slop][:default]
|
317
|
+
hash["hl.regex.slop"] = regex[:slop][:default]
|
318
|
+
end
|
319
|
+
if regex[:slop][:fields]
|
320
|
+
regex[:slop][:fields].each do |k,v|
|
321
|
+
hash["f.#{k}.hl.regex.slop"] = v
|
322
|
+
end
|
323
|
+
end
|
324
|
+
else
|
325
|
+
hash["hl.regex.slop"] = regex[:slop]
|
326
|
+
end
|
327
|
+
end
|
328
|
+
if regex[:pattern]
|
329
|
+
if regex[:pattern].kind_of? Hash
|
330
|
+
if regex[:pattern][:default]
|
331
|
+
hash["hl.regex.pattern"] = regex[:pattern][:default]
|
332
|
+
end
|
333
|
+
if regex[:pattern][:fields]
|
334
|
+
regex[:pattern][:fields].each do |k,v|
|
335
|
+
hash["f.#{k}.hl.regex.pattern"] = v
|
336
|
+
end
|
337
|
+
end
|
338
|
+
else
|
339
|
+
hash["hl.regex.pattern"] = regex[:pattern]
|
340
|
+
end
|
341
|
+
end
|
342
|
+
if regex[:max_analyzed_chars]
|
343
|
+
if regex[:max_analyzed_chars].kind_of? Hash
|
344
|
+
if regex[:max_analyzed_chars][:default]
|
345
|
+
hash["hl.regex.maxAnalyzedChars"] = regex[:max_analyzed_chars][:default]
|
346
|
+
end
|
347
|
+
if regex[:max_analyzed_chars][:fields]
|
348
|
+
regex[:max_analyzed_chars][:fields].each do |k,v|
|
349
|
+
hash["f.#{k}.hl.regex.maxAnalyzedChars"] = v
|
350
|
+
end
|
351
|
+
end
|
352
|
+
else
|
353
|
+
hash["hl.regex.maxAnalyzedChars"] = regex[:max_analyzed_chars]
|
354
|
+
end
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
end
|
359
|
+
|
360
|
+
if @params[:mlt]
|
361
|
+
hash[:mlt] = true
|
362
|
+
hash["mlt.count"] = @params[:mlt][:count]
|
363
|
+
hash["mlt.fl"] = @params[:mlt][:field_list].join(',')
|
364
|
+
hash["mlt.mintf"] = @params[:mlt][:min_term_freq]
|
365
|
+
hash["mlt.mindf"] = @params[:mlt][:min_doc_freq]
|
366
|
+
hash["mlt.minwl"] = @params[:mlt][:min_word_length]
|
367
|
+
hash["mlt.maxwl"] = @params[:mlt][:max_word_length]
|
368
|
+
hash["mlt.maxqt"] = @params[:mlt][:max_query_terms]
|
369
|
+
hash["mlt.maxntp"] = @params[:mlt][:max_tokens_parsed]
|
370
|
+
hash["mlt.boost"] = @params[:mlt][:boost]
|
371
|
+
end
|
372
|
+
|
373
|
+
hash.merge(super.to_hash)
|
374
|
+
end
|
375
|
+
|
376
|
+
end
|
@@ -0,0 +1,23 @@
|
|
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
|
+
# a parent class for all requests that go through the solr update handler
|
14
|
+
# TODO: Use new xml update handler for better error responses
|
15
|
+
class Solr::Request::Update < Solr::Request::Base
|
16
|
+
def response_format
|
17
|
+
:xml
|
18
|
+
end
|
19
|
+
|
20
|
+
def handler
|
21
|
+
'update'
|
22
|
+
end
|
23
|
+
end
|
data/lib/solr/request.rb
ADDED
@@ -0,0 +1,26 @@
|
|
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
|
+
module Solr; module Request; end; end
|
14
|
+
require 'solr/request/add_document'
|
15
|
+
require 'solr/request/modify_document'
|
16
|
+
require 'solr/request/base'
|
17
|
+
require 'solr/request/commit'
|
18
|
+
require 'solr/request/delete'
|
19
|
+
require 'solr/request/ping'
|
20
|
+
require 'solr/request/select'
|
21
|
+
require 'solr/request/standard'
|
22
|
+
require 'solr/request/spellcheck'
|
23
|
+
require 'solr/request/dismax'
|
24
|
+
require 'solr/request/update'
|
25
|
+
require 'solr/request/index_info'
|
26
|
+
require 'solr/request/optimize'
|
@@ -0,0 +1,17 @@
|
|
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
|
+
class Solr::Response::AddDocument < Solr::Response::Xml
|
14
|
+
def initialize(xml)
|
15
|
+
super
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,42 @@
|
|
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
|
+
class Solr::Response::Base
|
14
|
+
attr_reader :raw_response
|
15
|
+
|
16
|
+
def initialize(raw_response)
|
17
|
+
@raw_response = raw_response
|
18
|
+
end
|
19
|
+
|
20
|
+
# factory method for creating a Solr::Response::* from
|
21
|
+
# a request and the raw response content
|
22
|
+
def self.make_response(request, raw)
|
23
|
+
|
24
|
+
# make sure response format seems sane
|
25
|
+
unless [:xml, :ruby].include?(request.response_format)
|
26
|
+
raise Solr::Exception.new("unknown response format: #{request.response_format}" )
|
27
|
+
end
|
28
|
+
|
29
|
+
# TODO: Factor out this case... perhaps the request object should provide the response class instead? Or dynamically align by class name?
|
30
|
+
# Maybe the request itself could have the response handling features that get mixed in with a single general purpose response object?
|
31
|
+
|
32
|
+
begin
|
33
|
+
klass = eval(request.class.name.sub(/Request/,'Response'))
|
34
|
+
rescue NameError
|
35
|
+
raise Solr::Exception.new("unknown request type: #{request.class}")
|
36
|
+
else
|
37
|
+
klass.new(raw)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,17 @@
|
|
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
|
+
require 'rexml/xpath'
|
14
|
+
|
15
|
+
class Solr::Response::Commit < Solr::Response::Xml
|
16
|
+
end
|
17
|
+
|
@@ -0,0 +1,13 @@
|
|
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
|
+
class Solr::Response::Delete < Solr::Response::Xml; end
|
@@ -0,0 +1,20 @@
|
|
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
|
+
class Solr::Response::Dismax < Solr::Response::Standard
|
14
|
+
# no need for special processing
|
15
|
+
|
16
|
+
# FIXME: 2007-02-07 <coda.hale@gmail.com> -- The existence of this class indicates that
|
17
|
+
# the Request/Response pair architecture is a little hinky. Perhaps we could refactor
|
18
|
+
# out some of the most common functionality -- Common Query Parameters, Highlighting Parameters,
|
19
|
+
# Simple Facet Parameters, etc. -- into modules?
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
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
|
+
class Solr::Response::IndexInfo < Solr::Response::Ruby
|
14
|
+
def initialize(ruby_code)
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
def num_docs
|
19
|
+
return @data['index']['numDocs']
|
20
|
+
end
|
21
|
+
|
22
|
+
def field_names
|
23
|
+
return @data['fields'].keys
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,17 @@
|
|
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
|
+
class Solr::Response::ModifyDocument < Solr::Response::Xml
|
14
|
+
def initialize(xml)
|
15
|
+
super
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,14 @@
|
|
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
|
+
class Solr::Response::Optimize < Solr::Response::Commit
|
14
|
+
end
|
@@ -0,0 +1,28 @@
|
|
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
|
+
require 'rexml/xpath'
|
14
|
+
|
15
|
+
class Solr::Response::Ping < Solr::Response::Xml
|
16
|
+
|
17
|
+
def initialize(xml)
|
18
|
+
super
|
19
|
+
@ok = REXML::XPath.first(@doc, './solr/ping') ? true : false
|
20
|
+
end
|
21
|
+
|
22
|
+
# returns true or false depending on whether the ping
|
23
|
+
# was successful or not
|
24
|
+
def ok?
|
25
|
+
@ok
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,42 @@
|
|
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
|
+
class Solr::Response::Ruby < Solr::Response::Base
|
14
|
+
attr_reader :data, :header
|
15
|
+
|
16
|
+
def initialize(ruby_code)
|
17
|
+
super
|
18
|
+
begin
|
19
|
+
#TODO: what about pulling up data/header/response to ResponseBase,
|
20
|
+
# or maybe a new middle class like SelectResponseBase since
|
21
|
+
# all Select queries return this same sort of stuff??
|
22
|
+
# XML (&wt=xml) and Ruby (&wt=ruby) responses contain exactly the same structure.
|
23
|
+
# a goal of solrb is to make it irrelevant which gets used under the hood,
|
24
|
+
# but favor Ruby responses.
|
25
|
+
@data = eval(ruby_code)
|
26
|
+
@header = @data['responseHeader']
|
27
|
+
raise "response should be a hash" unless @data.kind_of? Hash
|
28
|
+
raise "response header missing" unless @header.kind_of? Hash
|
29
|
+
rescue SyntaxError => e
|
30
|
+
raise Solr::Exception.new("invalid ruby code: #{e}")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def ok?
|
35
|
+
@header['status'] == 0
|
36
|
+
end
|
37
|
+
|
38
|
+
def query_time
|
39
|
+
@header['QTime']
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|