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: 7b7e9ef2eebaa2f19801b68d9c5157e62dce2635 https://github.com/ranguba/groonga-client/commit/7b7e9ef2eebaa2f19801b68d9c5157e62dce2635 Message: 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 (+21 -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 (6c26d7a) @@ -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,27 @@ 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) && + record.first[1][1].none? {|key| key[0] == "_nsubrecs"} + @slices = {} + record.each do |key, slice_body| + n_hits, body = parse_match_records_v1(slice_body) + @slices[key] = body + 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 = {} + if body["slices"] + body["slices"].each do |key, records| + @slices[key] = parse_match_records_v3(records) + end + end end body end Modified: test/response/test-select-command-version1.rb (+60 -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 (bc55e36) @@ -1,5 +1,6 @@ # Copyright (C) 2013-2016 Kouhei Sutou <kou �� clear-code.com> # Copyright (C) 2013 Kosuke Asami +# Copyright (C) 2016 Masafumi Yokoyama <yokoyama �� clear-code.com> # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -315,5 +316,64 @@ 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) + @body = [ + [ + [3], + [ + [ + "_id", + "UInt32" + ], + [ + "tag", + "ShortText" + ] + ], + [1, "groonga"], + [2, "rroonga"], + [3, "groonga"], + ], + { + "groonga" => [ + [2], + [ + [ + "_id", + "UInt32" + ], + [ + "tag", + "ShortText" + ] + ], + [1, "groonga"], + [3, "groonga"], + ] + } + ] + end + + def test_slices + assert_equal({ + "groonga" => [ + {"_id" => 1, "tag" => "groonga"}, + {"_id" => 3, "tag" => "groonga"}, + ] + }, + slices(@body)) + end + + private + def slices(body) + create_response(body).slices + end + end end end -------------- next part -------------- HTML����������������������������... Télécharger