elasticsearch-explain-response 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f25f7c2844dcc655da1aba48907e8bf5d195202f
4
- data.tar.gz: 8cae38ace76385a9d0a22e93b561b0938f952b86
3
+ metadata.gz: ade43ddb3bce35fbc76c2f90457646665448a66a
4
+ data.tar.gz: 58d5df58953bad1dade17dce95826f923a85ebd7
5
5
  SHA512:
6
- metadata.gz: c18a63a09bfec6a3e1603d06f6af49bb9d69086d8ac1b6f2ad9f90c611568007644980a96cbdde9ced14aa56a0f7efba9b6985b4aa811adc705873c54b7bcd0c
7
- data.tar.gz: 2029b5396d5a7f62ca6f2bc4bb6791012e2440b2487b473c1d1d6c94a5e2e31c8755c7be6e6e3105113d3464a03ca7b28be2514d32d72971e4b5623a78124bd2
6
+ metadata.gz: c65535f7eb7d273fc89e41923eee15fc9a3d265e538f70d1c13baed4238365c513e780143518d33cf457923bede9cbee000cdf9e1727df1272a0750f84bac2b8
7
+ data.tar.gz: c89b690ab7dea90299acba77b7a60717029d42452271d5b1ff41fd178ec9fd5a77262590ee3eb6b9782918e66eb9d796f89c183b925cca0b96a06e4b2004f9d6
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "elasticsearch-explain-response"
7
- spec.version = "0.0.4"
7
+ spec.version = "0.0.5"
8
8
  spec.authors = ["Tomoya Hirano"]
9
9
  spec.email = ["hiranotomoya@gmail.com"]
10
10
  spec.summary = %q{Parser for Elasticserach Explain response}
@@ -9,6 +9,7 @@ module Elasticsearch
9
9
  def initialize(options = {})
10
10
  disable_colorization if options[:colorize] == false
11
11
  @max = options[:max] || 3
12
+ @plain_score = options[:plain_score] == true
12
13
  end
13
14
 
14
15
  def render(tree)
@@ -36,7 +37,7 @@ module Elasticsearch
36
37
  end
37
38
 
38
39
  def render_score(score)
39
- value = if score > 1_000
40
+ value = if !@plain_score && score > 1_000
40
41
  sprintf("%1.2g", score.round(2))
41
42
  else
42
43
  score.round(2).to_s
@@ -19,8 +19,8 @@ module Elasticsearch
19
19
  # Show scoring as a simple math formula
20
20
  # @example
21
21
  # "1.0 = (1.0(termFreq=1.0)) x 1.0(idf(2/3)) x 1.0(fieldNorm)"
22
- def render_in_line(result, max: nil)
23
- new(result["explanation"], max: max).render_in_line
22
+ def render_in_line(result, options = {})
23
+ new(result["explanation"], options).render_in_line
24
24
  end
25
25
 
26
26
  # Show scoring with indents
@@ -30,17 +30,17 @@ module Elasticsearch
30
30
  # 3.35 = 0.2 + 0.93 + 1.29 + 0.93
31
31
  # 54.3 = 54.3 min 3.4028234999999995e+38(maxBoost)
32
32
  # 54.3 = 2.0 x 10.0 x 3.0 x 0.91
33
- def render(result, max: nil)
34
- new(result["explanation"], max: max).render
33
+ def render(result, options = {})
34
+ new(result["explanation"], options).render
35
35
  end
36
36
  end
37
37
 
38
38
  attr_reader :explain
39
39
 
40
- def initialize(explain, max: nil, colorize: true)
40
+ def initialize(explain, options = {})
41
41
  @explain = explain
42
42
  @indent = 0
43
- @renderer = ExplainRenderer.new(max: max, colorize: colorize)
43
+ @renderer = ExplainRenderer.new({ colorize: true }.merge(options))
44
44
  end
45
45
 
46
46
  def render
@@ -52,10 +52,11 @@ describe Elasticsearch::API::Response::ExplainResponse do
52
52
 
53
53
  describe "#render" do
54
54
  let(:response) do
55
- described_class.new(fake_response["explanation"], max: max, colorize: false)
55
+ described_class.new(fake_response["explanation"], max: max, colorize: false, plain_score: plain_score)
56
56
  end
57
57
 
58
58
  let(:max) { nil }
59
+ let(:plain_score) { nil }
59
60
 
60
61
  subject do
61
62
  response.render.lines.map(&:rstrip)
@@ -87,6 +88,19 @@ describe Elasticsearch::API::Response::ExplainResponse do
87
88
  ])
88
89
  end
89
90
  end
91
+
92
+ context "with plain_score = true" do
93
+ let(:plain_score) { true }
94
+
95
+ it "returns summary of explain in lines" do
96
+ expect(subject).to match_array([
97
+ "0.05 = 0.11 x 0.5(coord(1/2)) x 1.0(queryBoost)",
98
+ " 0.11 = 0.11 min 3.4028235e+38",
99
+ " 0.11 = 0.11(weight(_all:smith))",
100
+ " 0.11 = 0.11(score)"
101
+ ])
102
+ end
103
+ end
90
104
  end
91
105
 
92
106
  describe "colorization" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticsearch-explain-response
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
  - Tomoya Hirano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-12 00:00:00.000000000 Z
11
+ date: 2015-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler