YUKI Hiroshi
null+****@clear*****
Wed Dec 4 20:42:44 JST 2013
YUKI Hiroshi 2013-12-04 20:42:44 +0900 (Wed, 04 Dec 2013) New Revision: 8195c27736ccce63f41fa7301672509ce37e7863 https://github.com/droonga/fluent-plugin-droonga/commit/8195c27736ccce63f41fa7301672509ce37e7863 Message: Define global option "no_output" for any mapper Modified files: lib/droonga/plugin/collector/basic.rb lib/droonga/plugin/distributor/search.rb test/unit/plugin/collector/test_basic.rb test/unit/plugin/distributor/test_search.rb Modified: lib/droonga/plugin/collector/basic.rb (+5 -5) =================================================================== --- lib/droonga/plugin/collector/basic.rb 2013-12-04 20:29:43 +0900 (357bac8) +++ lib/droonga/plugin/collector/basic.rb 2013-12-04 20:42:44 +0900 (69d461a) @@ -34,16 +34,16 @@ module Droonga case mapper["type"] when "count" result[element] = result[mapper["target"]].size - if mapper["drop_elements"] - mapper["drop_elements"].each do |drop_element| - result.delete(drop_element) - end - end when "sort" end end # phase 2: post-process elements.each do |element, mapper| + if mapper["no_output"] + result.delete(element) + next + end + case mapper["type"] when "count" when "sort" Modified: lib/droonga/plugin/distributor/search.rb (+5 -2) =================================================================== --- lib/droonga/plugin/distributor/search.rb 2013-12-04 20:29:43 +0900 (d2c42da) +++ lib/droonga/plugin/distributor/search.rb 2013-12-04 20:42:44 +0900 (d815775) @@ -59,6 +59,7 @@ module Droonga final_offset, final_limit = calculate_offset_and_limit!(query) elements = {} + no_output_records = false if output["elements"].include?("count") elements["count"] = { @@ -77,7 +78,7 @@ module Droonga final_limit = -1 output["elements"] << "records" output["attributes"] ||= ["_key"] - mapper["drop_elements"] = ["records"] + no_output_records = true end output_mapper[output_name]["elements"]["count"] = mapper end @@ -105,13 +106,15 @@ module Droonga # Instead, we apply "offset" on the gethering phase. elements["records"]["limit"] = output["limit"] - output_mapper[output_name]["elements"]["records"] = { + mapper = { "type" => "sort", "offset" => final_offset, "limit" => final_limit, "format" => final_format, "attributes" => final_attributes, } + mapper["no_output"] = true if no_output_records + output_mapper[output_name]["elements"]["records"] = mapper end reducer = { Modified: test/unit/plugin/collector/test_basic.rb (+1 -1) =================================================================== --- test/unit/plugin/collector/test_basic.rb 2013-12-04 20:29:43 +0900 (c444b6a) +++ test/unit/plugin/collector/test_basic.rb 2013-12-04 20:42:44 +0900 (4cb52e6) @@ -274,13 +274,13 @@ class BasicCollectorTest < Test::Unit::TestCase "count" => { "type" => "count", "target" => "records", - "drop_elements" => ["records"], }, "records" => { "type" => "sort", "format" => "simple", "attributes" => [], "limit" => -1, + "no_output" => true, }, }, }, Modified: test/unit/plugin/distributor/test_search.rb (+7 -7) =================================================================== --- test/unit/plugin/distributor/test_search.rb 2013-12-04 20:29:43 +0900 (08d6641) +++ test/unit/plugin/distributor/test_search.rb 2013-12-04 20:42:44 +0900 (abe170c) @@ -948,12 +948,11 @@ class SearchDistributorTest < Test::Unit::TestCase }, }) message << gatherer(envelope, :elements => { - "count" => count_mapper( - :drop_elements => ["records"], - ), + "count" => count_mapper, "records" => records_mapper( :limit => -1, :attributes => ["_key"], + :no_output => true, ), }) message << searcher(envelope, :output_offset => 0, @@ -1039,20 +1038,21 @@ class SearchDistributorTest < Test::Unit::TestCase "type" => "count", "target" => "records", } - if options[:drop_elements] - mapper["drop_elements"] = options[:drop_elements] - end mapper end def records_mapper(options={}) - { + mapper = { "type" => "sort", "offset" => options[:offset] || 0, "limit" => options[:limit] || 0, "format" => options[:format] || "simple", "attributes" => options[:attributes] || [], } + unless options[:no_output].nil? + mapper["no_output"] = options[:no_output] + end + mapper end def gatherer(search_request_envelope, options={}) -------------- next part -------------- HTML����������������������������... ダウンロード