YUKI Hiroshi
null+****@clear*****
Mon Feb 3 12:12:32 JST 2014
YUKI Hiroshi 2014-02-03 12:12:32 +0900 (Mon, 03 Feb 2014) New Revision: 69cc33f525d1cb6d829f2c52653e475f74f45ad9 https://github.com/droonga/fluent-plugin-droonga/commit/69cc33f525d1cb6d829f2c52653e475f74f45ad9 Message: Allow to define multiple reducers at once Modified files: lib/droonga/distributed_command_planner.rb lib/droonga/plugin/distributor/distributed_search_planner.rb Modified: lib/droonga/distributed_command_planner.rb (+22 -5) =================================================================== --- lib/droonga/distributed_command_planner.rb 2014-02-03 12:11:08 +0900 (f027a23) +++ lib/droonga/distributed_command_planner.rb 2014-02-03 12:12:32 +0900 (154d0cb) @@ -40,10 +40,18 @@ module Droonga @messages = unified_reducers + unified_gatherers + [fixed_processor] end - def reduce(name, reducer) - @reducers << reducer_message("reduce", name, reducer) - @gatherers << gatherer_message("gather", name) - @outputs << name + def reduce(params=nil) + return unless params + params.each do |name, reducer| + gatherer = nil + if reducer[:gather] + gatherer = reducer[:gather] + reducer = reducer[:reduce] + end + @reducers << reducer_message(reduce_command, name, reducer) + @gatherers << gatherer_message(gather_command, name, gatherer) + @outputs << name + end end def scatter(body=nil) @@ -77,6 +85,14 @@ module Droonga end private + def reduce_command + "reduce" + end + + def gather_command + "gather" + end + def unified_reducers unified_reducers = {} @reducers.each do |reducer| @@ -129,7 +145,8 @@ module Droonga } end - def gatherer_message(command, name, gatherer={}) + def gatherer_message(command, name, gatherer=nil) + gatherer ||= {} { "type" => command, "body" => { Modified: lib/droonga/plugin/distributor/distributed_search_planner.rb (+10 -9) =================================================================== --- lib/droonga/plugin/distributor/distributed_search_planner.rb 2014-02-03 12:11:08 +0900 (99beae5) +++ lib/droonga/plugin/distributor/distributed_search_planner.rb 2014-02-03 12:12:32 +0900 (7f7c1e1) @@ -45,6 +45,14 @@ module Droonga private UNLIMITED = -1 + def reduce_command + "search_reduce" + end + + def gather_command + "search_gather" + end + def ensure_unifiable! @queries.each do |name, query| if unifiable?(name) && query["output"] @@ -77,15 +85,8 @@ module Droonga elements = transformer.mappers mapper = {} mapper["elements"] = elements unless elements.empty? - reduce(input_name, - transformer.reducers, - mapper) - end - - def reduce(name, reducer, gatherer={}) - @reducers << reducer_message("search_reduce", name, reducer) - @gatherers << gatherer_message("search_gather", name, gatherer) - @outputs << name + reduce(input_name => { :reduce => transformer.reducers, + :gather => mapper }) end class QueryTransformer -------------- next part -------------- HTML����������������������������...Download