Masafumi Yokoyama
null+****@clear*****
Fri Dec 2 19:25:01 JST 2016
Masafumi Yokoyama 2016-12-02 19:25:01 +0900 (Fri, 02 Dec 2016) New Revision: d52784417c1f692cf019279aa7660b0dd603214a https://github.com/ranguba/groonga-client/commit/d52784417c1f692cf019279aa7660b0dd603214a Message: WIP: try to support slices for select command Modified files: lib/groonga/client/response/select.rb test/response/test-select-command-version1.rb Modified: lib/groonga/client/response/select.rb (+18 -1) =================================================================== --- lib/groonga/client/response/select.rb 2016-10-11 17:59:47 +0900 (b7c0af8) +++ lib/groonga/client/response/select.rb 2016-12-02 19:25:01 +0900 (114c706) @@ -37,6 +37,9 @@ module Groonga # Otherwise, `[drilldown1, drilldown2]` is returned. attr_accessor :drilldowns + # @return [::Hash<String, Groonga::Client::Response::Select>] + attr_accessor :slices + def body=(body) super(body) parse_body(body) @@ -46,10 +49,24 @@ module Groonga def parse_body(body) if body.is_a?(::Array) @n_hits, @records = parse_match_records_v1(body.first) - @drilldowns = parse_drilldowns_v1(body[1..-1]) + body[1..-1].each do |record| + if record.is_a?(::Hash) + @slices = {} + record.each do |key, slice_body| + @slices[key] = parse_body([slice_body]).first + end + else + @drilldowns = parse_drilldowns_v1(record) + end + end else @n_hits, @records = parse_match_records_v3(body) @drilldowns = parse_drilldowns_v3(body["drilldowns"]) + #@slices = parse_slices_v3(body["slices"]) + @slices = {} + body["slices"].each do |key, records| + @slices[key] = parse_match_records_v3(records) + end end body end Modified: test/response/test-select-command-version1.rb (+83 -0) =================================================================== --- test/response/test-select-command-version1.rb 2016-10-11 17:59:47 +0900 (5a76457) +++ test/response/test-select-command-version1.rb 2016-12-02 19:25:01 +0900 (bb8d44b) @@ -287,6 +287,7 @@ class TestResponseSelectCommandVersion1 < Test::Unit::TestCase ], }, ] + p body assert_equal({ "tag" => [ {"_key" => "Groonga", "_nsubrecs" => 2}, @@ -315,5 +316,87 @@ class TestResponseSelectCommandVersion1 < Test::Unit::TestCase values end end + + class TestSlices < self + def setup + pair_arguments = { + "slices[groonga].filter" => 'tag @ "groonga"', + } + @command = Groonga::Command::Select.new("select", pair_arguments) + end + + def test_n_hits + body = [ + [ + [3], + [ + [ + "_id", + "UInt32" + ], + [ + "tag", + "ShortText" + ] + ], + [ + [1, "groonga"], + [2, "rroonga"], + [3, "groonga"], + ] + ], + { + "groonga": [ + [2], + [ + [ + "_id", + "UInt32" + ], + [ + "tag", + "ShortText" + ] + ], + [ + [1, "groonga"], + [3, "groonga"], + ] + ] + } + ] + assert_equal([29], + slices(body)) + end + + def test_items + body = [ + [[0], []], + [ + [29], + [ + ["_key", "ShortText"], + ["_nsubrecs", "Int32"], + ], + ["groonga", 29], + ["Ruby", 19], + ["rroonga", 9], + ], + ] + assert_equal([ + [ + {"_key" => "groonga", "_nsubrecs" => 29}, + {"_key" => "Ruby", "_nsubrecs" => 19}, + {"_key" => "rroonga", "_nsubrecs" => 9}, + ], + ], + slices(body).collect(&:items)) + end + + private + def slices(body) + create_response(body).slices + end + end end end -------------- next part -------------- HTML����������������������������...Download