cheap_skate 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -59,6 +59,16 @@ END
59
59
  <lst name="responseHeader"><int name="status">0</int><int name="QTime">1</int><lst name="params"><str name="echoParams">all</str><str name="echoParams">all</str><str name="q">solrpingquery</str><str name="qt">standard</str></lst></lst><str name="status">OK</str>
60
60
  </response>'
61
61
  end
62
+
63
+ get '/admin/luke/' do
64
+ luke = options.index.luke(params)
65
+ wt = params["wt"] || "json"
66
+ luke.query_time = qtime
67
+ if wt == "json"
68
+ content_type 'application/json', :charset => 'utf-8'
69
+ end
70
+ luke.send("as_#{wt}")
71
+ end
62
72
 
63
73
  before do
64
74
  if options.prefix_path
@@ -222,5 +222,81 @@ module CheapSkate
222
222
  d.index = self
223
223
  d
224
224
  end
225
+
226
+ def luke(params)
227
+ response = LukeResponse.new
228
+ response.num_docs = reader.num_docs
229
+ response.max_doc = reader.max_doc
230
+ response.version = reader.version
231
+ response.optimized = true # Hard code this -- not sure there's any way to get this from Ferret
232
+ response.current = reader.version == writer.version
233
+ response.has_deletions = reader.has_deletions?
234
+ response.directory = options[:path]
235
+ response.last_modified = Time.now.xmlschema # I don't see this in Ferret, either
236
+ reader.field_infos.each do | field |
237
+ schema_field = schema.fields[field.name]
238
+ if schema_field
239
+ luke_field = {:type=>schema_field[:type]}
240
+ multivalued = schema.multi_valued?(field.name)
241
+ else
242
+ luke_field = {:type=>"text"}
243
+ multivalued = true
244
+ end
245
+ schema_string = ""
246
+ schema_string << case field.indexed?
247
+ when true then "I"
248
+ else "-"
249
+ end
250
+ schema_string << case field.tokenized?
251
+ when true then "T"
252
+ else "-"
253
+ end
254
+
255
+ schema_string << case field.stored?
256
+ when true then "S"
257
+ else "-"
258
+ end
259
+
260
+ schema_string << case multivalued
261
+ when true then "M"
262
+ else "-"
263
+ end
264
+
265
+ schema_string << case field.store_term_vector?
266
+ when true then "V"
267
+ else "-"
268
+ end
269
+
270
+ schema_string << case field.store_offsets?
271
+ when true then "o"
272
+ else "-"
273
+ end
274
+
275
+ schema_string << case field.store_positions?
276
+ when true then "p"
277
+ else "-"
278
+ end
279
+
280
+ schema_string << case field.omit_norms?
281
+ when true then "O"
282
+ else "-"
283
+ end
284
+ schema_string << "--"
285
+
286
+ schema_string << case field.compressed?
287
+ when true then "C"
288
+ else "-"
289
+ end
290
+
291
+ schema_string << "--"
292
+ response.fields[field.name] = {:schema=>schema_string}
293
+ #terms = {}
294
+ #reader.terms(field.name).each do |term, count|
295
+ # terms[term] = count
296
+ #end
297
+
298
+ end
299
+ response
300
+ end
225
301
  end
226
302
  end
@@ -312,4 +312,28 @@ end
312
312
  class Query
313
313
  attr_accessor :parser, :query, :filter, :filter_proc
314
314
  end
315
+
316
+ class LukeResponse
317
+ attr_accessor :status, :query_time, :num_docs, :max_doc, :version, :optimized, :current, :has_deletions, :directory, :last_modified,
318
+ :fields, :key
319
+ def initialize
320
+ @status = 0
321
+ @key = {"I"=>"Indexed", "T"=>"Tokenized", "S"=>"Stored", "M"=>"Multivalued", "V"=>"TermVector Stored",
322
+ "o"=>"Store Offset With TermVector", "p"=>"Store Position With TermVector", "O"=>"Omit Norms",
323
+ "L"=>"Lazy","B"=>"Binary","C"=>"Compressed","f"=>"Sort Missing First","l"=>"Sort Missing Last"}
324
+ @fields = {}
325
+ end
326
+
327
+ def to_hash
328
+ hsh = {"responseHeader"=>{"status" => @status, "QTime"=>@query_time}, "index"=>{"numDocs"=>@num_docs, "maxDoc"=>@max_doc, "version"=>@version, "optimized"=>@optimized, "current"=>@current, "hasDeletions"=>@has_deletions, "directory"=>@directory, "lastModified"=>@last_modified}, "fields"=>@fields, "key"=>@key}
329
+ end
330
+
331
+ def as_ruby
332
+ return to_hash
333
+ end
334
+
335
+ def as_json
336
+ return to_hash.to_json
337
+ end
338
+ end
315
339
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 8
9
- version: 0.0.8
8
+ - 9
9
+ version: 0.0.9
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ross Singer