log_magic 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 733121449aea416c67e1d0e5ab5d22c131465637
4
- data.tar.gz: a9f0223530f33b7c4e978105de1287f9c8603250
3
+ metadata.gz: 86b235416d827dc6a190d2098a617b72cbafb3bf
4
+ data.tar.gz: b3ff933f789f7bb66a8331181b75589fd4452d3c
5
5
  SHA512:
6
- metadata.gz: ed64f68737ca9ca07819d6848ab8bd056ee79add352fbbf3915f5e74e21607f24f5be99535109542275b542e2388d039968a4ad3bbd8f516676f551e8c4a43eb
7
- data.tar.gz: cbd911866995b70530d3d39bc43bb150fd95441798e0bc5c24edcdc46787f4dc754edd8d7335ff399c9991b4e5e08a1aa1ad40157793faa8e1a3adb276e1e39f
6
+ metadata.gz: 2ff908f15c4906c78f1b2436e62f4e2dbe24b26436c6acf6e514f95fc856bccc7cfc922730fdda0c269627210b44484a2f7ce75540a6fd306a1c2ab4184bdc47
7
+ data.tar.gz: 3ec53d4f8b0e60c98900a96f3608dc0a2e6f8fad2b95d50e2da4a0261361532452455611462eb230f0f276717f6542d9fccdb400259947afad2fe30ffba021b1
@@ -1,4 +1,2 @@
1
- %h2
2
- This query contains a
3
- %a{href: 'https://www.elastic.co/guide/en/elasticsearch/guide/current/_boosting_query_clauses.html'}
4
- Boost Query Clause
1
+ %a{href: 'https://www.elastic.co/guide/en/elasticsearch/guide/current/_boosting_query_clauses.html'}
2
+ 'boost'
@@ -1,4 +1,2 @@
1
- %h2
2
- This query contains a
3
- %a{href: 'https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-dis-max-query.html'}
4
- Dis Max Query
1
+ %a{href: 'https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-dis-max-query.html'}
2
+ 'dis_max'
@@ -1,4 +1,2 @@
1
- %h2
2
- This query contains a
3
- %a{href: 'https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html'}
4
- Match query
1
+ %a{href: 'https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html'}
2
+ 'match'
@@ -0,0 +1,2 @@
1
+ %p
2
+ = query_json
@@ -1,8 +1,5 @@
1
- - explainer_sections.each do |explainer_section|
2
- = explainer_section.explanation
3
-
4
- = settings_explainer_section.explanation
5
-
6
1
  %h2 Query
7
2
  %p
8
- = pretty_print_json(query_json)
3
+ = explained_query.explanation
4
+
5
+ = settings_explainer_section.explanation
@@ -5,12 +5,8 @@ class LogMagic::SearchkickExplainer::BoostExplainerSection
5
5
  @query_json = query_json
6
6
  end
7
7
 
8
- def matches?
9
- @query_json =~ /[^\w]boost[^\w]/
10
- end
11
-
12
- def explanation
13
- rendered_template
8
+ def match_regex
9
+ /[^\w]boost[^\w]/
14
10
  end
15
11
 
16
12
  def template_name
@@ -5,12 +5,8 @@ class LogMagic::SearchkickExplainer::DisMaxExplainerSection
5
5
  @query_json = query_json
6
6
  end
7
7
 
8
- def matches?
9
- @query_json =~ /[^\w]dis_max[^\w]/
10
- end
11
-
12
- def explanation
13
- rendered_template
8
+ def match_regex
9
+ /[^\w]dis_max[^\w]/
14
10
  end
15
11
 
16
12
  def template_name
@@ -5,12 +5,8 @@ class LogMagic::SearchkickExplainer::MatchExplainerSection
5
5
  @query_json = query_json
6
6
  end
7
7
 
8
- def matches?
9
- @query_json =~ /[^\w]match[^\w]/
10
- end
11
-
12
- def explanation
13
- rendered_template
8
+ def match_regex
9
+ /[^\w]match[^\w]/
14
10
  end
15
11
 
16
12
  def template_name
@@ -0,0 +1,34 @@
1
+ class LogMagic::SearchkickExplainer::QueryExplainerSection
2
+ include ::LogMagic::TemplatingUtils
3
+ include ::LogMagic::JSONUtils
4
+ attr_reader :query_json
5
+
6
+ def initialize(query_json)
7
+ @query_json = pretty_print_json(query_json)
8
+ enriche_query_json
9
+ end
10
+
11
+ def explanation
12
+ rendered_template
13
+ end
14
+
15
+ def template_name
16
+ 'query.haml'
17
+ end
18
+
19
+ def explainer_section_classes
20
+ [
21
+ ::LogMagic::SearchkickExplainer::DisMaxExplainerSection,
22
+ ::LogMagic::SearchkickExplainer::BoostExplainerSection,
23
+ ::LogMagic::SearchkickExplainer::MatchExplainerSection
24
+ ]
25
+ end
26
+
27
+ def enriche_query_json
28
+ explainer_section_classes.map do |explainer_section_class|
29
+ explainer_section_class.new(query_json)
30
+ end.select do |explainer_section|
31
+ explainer_section.enriche
32
+ end
33
+ end
34
+ end
@@ -5,8 +5,8 @@ require 'haml'
5
5
  class LogMagic::SearchkickExplainer
6
6
  include ::LogMagic::JSONUtils
7
7
  include ::LogMagic::TemplatingUtils
8
-
9
- def initialize()
8
+
9
+ def initialize
10
10
  @persistance_layer = ::LogMagic::PersistanceLayer.new
11
11
  end
12
12
 
@@ -22,20 +22,8 @@ class LogMagic::SearchkickExplainer
22
22
  SettingsExplainerSection.new(elasticsearch_url)
23
23
  end
24
24
 
25
- def explainer_section_classes
26
- [
27
- DisMaxExplainerSection,
28
- BoostExplainerSection,
29
- MatchExplainerSection
30
- ]
31
- end
32
-
33
- def explainer_sections
34
- explainer_section_classes.map do |explainer_section_class|
35
- explainer_section_class.new(query_json)
36
- end.select do |explainer_section|
37
- explainer_section.matches?
38
- end
25
+ def explained_query
26
+ QueryExplainerSection.new(query_json)
39
27
  end
40
28
 
41
29
  def start
@@ -9,4 +9,8 @@ module LogMagic::TemplatingUtils
9
9
  File.join(__FILE__, '..', '..', 'explainer_templates', template_name)
10
10
  )
11
11
  end
12
+
13
+ def enriche
14
+ @query_json.gsub!(match_regex, rendered_template)
15
+ end
12
16
  end
data/lib/log_magic.rb CHANGED
@@ -57,4 +57,5 @@ require 'log_magic/explainers/explainer_sections/dis_max_explainer'
57
57
  require 'log_magic/explainers/explainer_sections/match_explainer'
58
58
  require 'log_magic/explainers/explainer_sections/boost_explainer'
59
59
  require 'log_magic/explainers/explainer_sections/settings_explainer'
60
+ require 'log_magic/explainers/explainer_sections/query_explainer'
60
61
  require 'log_magic/persistance_layer'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log_magic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manuel Korfmann
@@ -108,11 +108,13 @@ files:
108
108
  - lib/log_magic/explainer_templates/boost.haml
109
109
  - lib/log_magic/explainer_templates/dis_max.haml
110
110
  - lib/log_magic/explainer_templates/match.haml
111
+ - lib/log_magic/explainer_templates/query.haml
111
112
  - lib/log_magic/explainer_templates/searchkick.haml
112
113
  - lib/log_magic/explainer_templates/settings.haml
113
114
  - lib/log_magic/explainers/explainer_sections/boost_explainer.rb
114
115
  - lib/log_magic/explainers/explainer_sections/dis_max_explainer.rb
115
116
  - lib/log_magic/explainers/explainer_sections/match_explainer.rb
117
+ - lib/log_magic/explainers/explainer_sections/query_explainer.rb
116
118
  - lib/log_magic/explainers/explainer_sections/settings_explainer.rb
117
119
  - lib/log_magic/explainers/searchkick_explainer.rb
118
120
  - lib/log_magic/log_listener.rb