groonga-client 0.5.1 → 0.5.2

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: b8a5665848bb07469199965c91102537be1de8ba
4
- data.tar.gz: b199fc33a43d039152d4ba068c415259bc4da524
3
+ metadata.gz: 98c07600cda5089240101c97f1055cee06406515
4
+ data.tar.gz: c26124ec4e3364a316949bb21bb9fbc00cac6661
5
5
  SHA512:
6
- metadata.gz: 9206ea5d72f485a6a47b02bcd4518efe6e1893cc1f462432ac9d9afd67cfb88b3faee72c574e516bad9c76485d94a6efddb9246049773230864c414144a0444c
7
- data.tar.gz: 39403cfa11da317eb5e17754a7f637234f2c250b2dd62922f501dcc2c0888afa3c74bf849573e61da0d3d14acb1f5b76b7ea7b230fa389b378a2d033017a8aa4
6
+ metadata.gz: d3aeb65b3107c978fdfef99efe64aadc4a5fd7c5ed4a4835c6377d2d1910acb795994e923ac2cd7bed0737d89740999e8a2c50f511ac762b2797593ad0be4e04
7
+ data.tar.gz: dedc41cf9ce0f590bb557574d310d55a02cff6c033eec799ff30253093e18182c1141a9801eed0d8aee46df5c583b936511560d9905aabe673aaf2abaf3f78ef
data/doc/text/news.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # NEWS
2
2
 
3
+ ## 0.5.2 - 2017-09-27
4
+
5
+ ### Improvements
6
+
7
+ * `Groonga::Client::Request::Select`: Added XML output support.
8
+
3
9
  ## 0.5.1 - 2017-08-21
4
10
 
5
11
  ### Improvements
@@ -93,18 +93,10 @@ module Groonga
93
93
 
94
94
  private
95
95
  def parse_xml(response)
96
- # FIXME: Use more fast XML parser
97
- # Extract as a class
98
96
  document = REXML::Document.new(response)
99
- root_element = document.root
100
- if root_element.name == "RESULT"
101
- result_element = root_element
102
- header = parse_xml_header(result_element)
103
- body = parse_xml_body(result_element.elements[1])
104
- else
105
- header = nil
106
- body = parse_xml_body(root_element)
107
- end
97
+ result_element = document.root
98
+ header = parse_xml_header(result_element)
99
+ body = parse_xml_body(result_element.elements[1])
108
100
  [header, body]
109
101
  end
110
102
 
@@ -24,6 +24,84 @@ module Groonga
24
24
  class Select < Base
25
25
  Response.register("select", self)
26
26
 
27
+ class << self
28
+ private
29
+ def parse_xml(response)
30
+ document = REXML::Document.new(response)
31
+ return super if document.root.name == "RESULT"
32
+
33
+ result_page = document.elements["SEGMENTS/SEGMENT/RESULTPAGE"]
34
+ result_set = result_page.elements["RESULTSET"]
35
+ n_hits, columns, records = parse_xml_result_set(result_set)
36
+
37
+ navigation_entry = result_page.elements["NAVIGATIONENTRY"]
38
+ drilldowns = parse_xml_navigation_entry(navigation_entry)
39
+
40
+ header = nil
41
+ body = [
42
+ [
43
+ [n_hits],
44
+ columns,
45
+ *records,
46
+ ],
47
+ *drilldowns,
48
+ ]
49
+ [header, body]
50
+ end
51
+
52
+ def parse_xml_result_set(result_set)
53
+ n_hits = Integer(result_set.attributes["NHITS"])
54
+
55
+ columns = []
56
+ records = []
57
+ result_set.each_element("HIT") do |hit|
58
+ if columns.empty?
59
+ hit.each_element("FIELD") do |field|
60
+ name = field.attributes["NAME"]
61
+ columns << [name, "ShortText"]
62
+ end
63
+ end
64
+ record = []
65
+ hit.each_element("FIELD") do |field|
66
+ record << field.text
67
+ end
68
+ records << record
69
+ end
70
+
71
+ [n_hits, columns, records]
72
+ end
73
+
74
+ def parse_xml_navigation_entry(navigation_entry)
75
+ return [] if navigation_entry.nil?
76
+
77
+ drilldowns = []
78
+ navigation_entry.each_element("NAVIGATIONELEMENTS") do |elements|
79
+ n_hits = Integer(elements.attributes["COUNT"])
80
+ columns = []
81
+ drilldown = []
82
+ elements.each_element("NAVIGATIONELEMENT") do |element|
83
+ if columns.empty?
84
+ element.attributes.each do |name, value|
85
+ columns << [name, "ShortText"]
86
+ end
87
+ end
88
+
89
+ drilldown << element.attributes.collect do |_, value|
90
+ value
91
+ end
92
+ end
93
+
94
+ drilldowns << [
95
+ [n_hits],
96
+ columns,
97
+ *drilldown,
98
+ ]
99
+ end
100
+
101
+ drilldowns
102
+ end
103
+ end
104
+
27
105
  include Enumerable
28
106
 
29
107
  # @return [Integer] The number of records that match againt
@@ -16,6 +16,6 @@
16
16
 
17
17
  module Groonga
18
18
  class Client
19
- VERSION = "0.5.1"
19
+ VERSION = "0.5.2"
20
20
  end
21
21
  end
@@ -16,9 +16,18 @@
16
16
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
 
18
18
  module TestResponseHelper
19
- def parse_raw_response(command_name, raw_response)
19
+ def parse_raw_response_raw(command_name, pair_arguments, raw_response)
20
20
  command_class = Groonga::Command.find(command_name)
21
- command = command_class.new(command_name, {})
21
+ command = command_class.new(command_name, pair_arguments)
22
22
  Groonga::Client::Response.parse(command, raw_response)
23
23
  end
24
+
25
+ def parse_raw_response(command_name, raw_response)
26
+ parse_raw_response_raw(command_name, {}, raw_response)
27
+ end
28
+
29
+ def parse_raw_xml_response(command_name, raw_response)
30
+ parse_raw_response_raw(command_name, {"output_type" => "xml"},
31
+ raw_response)
32
+ end
24
33
  end
@@ -0,0 +1,105 @@
1
+ # Copyright (C) 2017 Kouhei Sutou <kou@clear-code.com>
2
+ #
3
+ # This library is free software; you can redistribute it and/or
4
+ # modify it under the terms of the GNU Lesser General Public
5
+ # License as published by the Free Software Foundation; either
6
+ # version 2.1 of the License, or (at your option) any later version.
7
+ #
8
+ # This library is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # Lesser General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU Lesser General Public
14
+ # License along with this library; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
+
17
+ require "response/helper"
18
+
19
+ class TestResponseSelectXML < Test::Unit::TestCase
20
+ include TestResponseHelper
21
+
22
+ def drilldown(key, n_hits, records)
23
+ Groonga::Client::Response::Select::Drilldown.new(key, n_hits, records)
24
+ end
25
+
26
+ def test_basic
27
+ raw_response = <<-XML
28
+ <?xml version="1.0" encoding="utf-8"?>
29
+ <SEGMENTS>
30
+ <SEGMENT>
31
+ <RESULTPAGE>
32
+ <RESULTSET OFFSET="0" LIMIT="1" NHITS="100">
33
+ <HIT NO="1">
34
+ <FIELD NAME="_id">1</FIELD>
35
+ </HIT>
36
+ </RESULTSET>
37
+ </RESULTPAGE>
38
+ </SEGMENT>
39
+ </SEGMENTS>
40
+ XML
41
+
42
+ response = parse_raw_xml_response("select", raw_response)
43
+ assert_equal({
44
+ :return_code => 0,
45
+ :start_time => Time.at(0),
46
+ :elapsed_time => 0.0,
47
+ :records => [{"_id" => "1"}],
48
+ },
49
+ {
50
+ :return_code => response.return_code,
51
+ :start_time => response.start_time,
52
+ :elapsed_time => response.elapsed_time,
53
+ :records => response.records,
54
+ })
55
+ end
56
+
57
+ def test_drilldown
58
+ raw_response = <<-XML
59
+ <?xml version="1.0" encoding="utf-8"?>
60
+ <SEGMENTS>
61
+ <SEGMENT>
62
+ <RESULTPAGE>
63
+ <RESULTSET OFFSET="0" LIMIT="0" NHITS="100">
64
+ </RESULTSET>
65
+ <NAVIGATIONENTRY>
66
+ <NAVIGATIONELEMENTS COUNT="7">
67
+ <NAVIGATIONELEMENT _key="2.2.0" _nsubrecs="18044" />
68
+ <NAVIGATIONELEMENT _key="2.3.0" _nsubrecs="18115" />
69
+ <NAVIGATIONELEMENT _key="2.4.0" _nsubrecs="14594" />
70
+ </NAVIGATIONELEMENTS>
71
+ </NAVIGATIONENTRY>
72
+ </RESULTPAGE>
73
+ </SEGMENT>
74
+ </SEGMENTS>
75
+ XML
76
+
77
+ response = parse_raw_response_raw("select",
78
+ {
79
+ "drilldown" => "version",
80
+ "output_type" => "xml",
81
+ },
82
+ raw_response)
83
+ drilldown_records = [
84
+ {"_key" => "2.2.0", "_nsubrecs" => "18044"},
85
+ {"_key" => "2.3.0", "_nsubrecs" => "18115"},
86
+ {"_key" => "2.4.0", "_nsubrecs" => "14594"},
87
+ ]
88
+ assert_equal({
89
+ :return_code => 0,
90
+ :start_time => Time.at(0),
91
+ :elapsed_time => 0.0,
92
+ :records => [],
93
+ :drilldowns => [
94
+ drilldown("version", 7, drilldown_records),
95
+ ],
96
+ },
97
+ {
98
+ :return_code => response.return_code,
99
+ :start_time => response.start_time,
100
+ :elapsed_time => response.elapsed_time,
101
+ :records => response.records,
102
+ :drilldowns => response.drilldowns,
103
+ })
104
+ end
105
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: groonga-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Haruka Yoshihara
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-08-21 00:00:00.000000000 Z
13
+ date: 2017-09-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: gqtp
@@ -240,6 +240,7 @@ files:
240
240
  - test/response/test-schema.rb
241
241
  - test/response/test-select-command-version1.rb
242
242
  - test/response/test-select-command-version3.rb
243
+ - test/response/test-select-xml.rb
243
244
  - test/response/test-status.rb
244
245
  - test/response/test-table-create.rb
245
246
  - test/response/test-table-list.rb
@@ -298,6 +299,7 @@ test_files:
298
299
  - test/response/test-error.rb
299
300
  - test/response/test-table-list.rb
300
301
  - test/response/test-status.rb
302
+ - test/response/test-select-xml.rb
301
303
  - test/response/test-schema.rb
302
304
  - test/response/test-select-command-version3.rb
303
305
  - test/response/test-select-command-version1.rb