Class: SolrLite::Explainer

Inherits:
Object
  • Object
show all
Defined in:
lib/explainer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(solr_reponse_hash) ⇒ Explainer

solr_response_hash a Solr HTTP response parsed via JSON.parse()



7
8
9
10
11
12
13
14
# File 'lib/explainer.rb', line 7

def initialize(solr_reponse_hash)
  @explain = solr_reponse_hash.fetch("debug", {}).fetch("explain", [])
  @entries = @explain.map do |ex|
    key = ex[0]
    text = ex[1]
    ExplainEntry.new(ex[0], ex[1])
  end
end

Instance Attribute Details

#entriesObject

Returns the value of attribute entries.



4
5
6
# File 'lib/explainer.rb', line 4

def entries
  @entries
end

Class Method Details

.from_response(solr_response) ⇒ Object

solr_response (string) is the Solr HTTP response from a query



17
18
19
20
# File 'lib/explainer.rb', line 17

def self.from_response(solr_response)
  hash = JSON.parse(solr_response)
  Explainer.new(hash)
end

Instance Method Details

#textObject

Raw string with the explain information for each entry



23
24
25
26
27
28
29
30
31
32
# File 'lib/explainer.rb', line 23

def text()
  text = ""
  @entries.each do |entry|
    text += "-- #{entry.key} {\r\n"
    text += "#{entry.text}\r\n"
    text += "}\r\n"
    text += "\r\n"
  end
  text
end