class Elasticsearch::API::Response::ExplainResponse
Parse Elasticsearch
Explain API
response json and display them in a neat way
@example
require 'elasticsearch' client = Elasticsearch::Client.new result = client.explain index: "megacorp", type: "employee", id: "1", q: "last_name:Smith" Elasticsearch::API::Response::ExplainResponse.new(result["explanation"]).render_in_line #=> "1.0 = (1.0(termFreq=1.0)) x 1.0(idf(2/3)) x 1.0(fieldNorm)"
Attributes
explain[R]
rendering_options[R]
trim[R]
Public Class Methods
new(explain, options = {})
click to toggle source
# File lib/elasticsearch/api/response/explain_response.rb, line 47 def initialize(explain, options = {}) @explain = explain || {} @indent = 0 @trim = options.has_key?(:trim) ? options.delete(:trim) : true @rendering_options = options parse_details end
render(result, options = {}, &block)
click to toggle source
Show scoring with indents @example
60.62 = 1.12 x 54.3 x 1.0(queryBoost) 1.12 = 3.35 x 0.33(coord(4/12)) 3.35 = 0.2 + 0.93 + 1.29 + 0.93 54.3 = 54.3 min 3.4028234999999995e+38(maxBoost) 54.3 = 2.0 x 10.0 x 3.0 x 0.91
# File lib/elasticsearch/api/response/explain_response.rb, line 36 def render(result, options = {}, &block) new(result["explanation"], options).render(&block) end
render_in_line(result, options = {}, &block)
click to toggle source
Show scoring as a simple math formula @example
"1.0 = (1.0(termFreq=1.0)) x 1.0(idf(2/3)) x 1.0(fieldNorm)"
# File lib/elasticsearch/api/response/explain_response.rb, line 25 def render_in_line(result, options = {}, &block) new(result["explanation"], options).render_in_line(&block) end
result_as_hash(result, options = {})
click to toggle source
# File lib/elasticsearch/api/response/explain_response.rb, line 40 def result_as_hash(result, options = {}) new(result["explanation"], options).render_as_hash end
Public Instance Methods
render(&block)
click to toggle source
# File lib/elasticsearch/api/response/explain_response.rb, line 56 def render(&block) @root.render(rendering_options, &block) end
render_as_hash(&block)
click to toggle source
# File lib/elasticsearch/api/response/explain_response.rb, line 64 def render_as_hash(&block) @root.render_as_hash(rendering_options, &block) end
render_in_line(&block)
click to toggle source
# File lib/elasticsearch/api/response/explain_response.rb, line 60 def render_in_line(&block) @root.render_in_line(rendering_options, &block) end
Private Instance Methods
parse_details()
click to toggle source
# File lib/elasticsearch/api/response/explain_response.rb, line 70 def parse_details @root ||= begin tree = ExplainParser.new.parse(explain) tree = ExplainTrimmer.new.trim(tree) if trim tree end end