Class: LogMagic::SearchkickExplainer::CustomAnalyzerHover

Inherits:
Object
  • Object
show all
Defined in:
lib/log_magic/explainers/searchkick/custom_analyzer_hover.rb

Instance Method Summary collapse

Constructor Details

#initialize(query_explainer, index_settings) ⇒ CustomAnalyzerHover

Returns a new instance of CustomAnalyzerHover.



4
5
6
7
# File 'lib/log_magic/explainers/searchkick/custom_analyzer_hover.rb', line 4

def initialize(query_explainer, index_settings)
  @query_explainer = query_explainer
  @index_settings = JSON.parse(index_settings)
end

Instance Method Details

#custom_analyzer_matcherObject



23
24
25
# File 'lib/log_magic/explainers/searchkick/custom_analyzer_hover.rb', line 23

def custom_analyzer_matcher
  /[^w]analyzer[^w]\n[^<]*<\/a>\n:&nbsp;"([^"]*)"/
end

#enricheObject



9
10
11
12
13
# File 'lib/log_magic/explainers/searchkick/custom_analyzer_hover.rb', line 9

def enriche
  @query_explainer.query_json.clone.scan(custom_analyzer_matcher) do |match|
    inject_hover(match[0])
  end
end

#hover_template(match) ⇒ Object



19
20
21
# File 'lib/log_magic/explainers/searchkick/custom_analyzer_hover.rb', line 19

def hover_template(match)
  ::LogMagic::HoverRenderer.new(match, HashDeepSearch.new(@index_settings).search(match))
end

#inject_hover(match) ⇒ Object



15
16
17
# File 'lib/log_magic/explainers/searchkick/custom_analyzer_hover.rb', line 15

def inject_hover(match)
  @query_explainer.query_json.sub!(/[^w]#{match}[^w]/, hover_template(match).rendered_template)
end