YUKI Hiroshi
null+****@clear*****
Tue Apr 21 21:54:22 JST 2015
YUKI Hiroshi 2015-04-21 21:54:22 +0900 (Tue, 21 Apr 2015) New Revision: e897a71069248b4a35b47f0acac5ad89aaac9176 https://github.com/droonga/droonga-engine/commit/e897a71069248b4a35b47f0acac5ad89aaac9176 Message: Separate "recursive-sum" collector from "sum". Because recursive sum can be slow. Copied files: lib/droonga/collectors/recursive_sum.rb (from lib/droonga/collectors.rb) Modified files: lib/droonga/collectors.rb lib/droonga/plugins/system/object_count.rb lib/droonga/reducer.rb Modified: lib/droonga/collectors.rb (+2 -1) =================================================================== --- lib/droonga/collectors.rb 2015-04-21 21:47:50 +0900 (4d88169) +++ lib/droonga/collectors.rb 2015-04-21 21:54:22 +0900 (b7d1f2d) @@ -1,4 +1,4 @@ -# Copyright (C) 2014 Droonga Project +# Copyright (C) 2014-2015 Droonga Project # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -16,3 +16,4 @@ require "droonga/collectors/and" require "droonga/collectors/or" require "droonga/collectors/sum" +require "droonga/collectors/recursive_sum" Copied: lib/droonga/collectors/recursive_sum.rb (+12 -4) 76% =================================================================== --- lib/droonga/collectors.rb 2015-04-21 21:47:50 +0900 (4d88169) +++ lib/droonga/collectors/recursive_sum.rb 2015-04-21 21:54:22 +0900 (110ff4d) @@ -1,4 +1,4 @@ -# Copyright (C) 2014 Droonga Project +# Copyright (C) 2015 Droonga Project # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -13,6 +13,14 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -require "droonga/collectors/and" -require "droonga/collectors/or" -require "droonga/collectors/sum" +module Droonga + module Collectors + class RecursiveSum + class << self + def operator + "recursive-sum" + end + end + end + end +end Modified: lib/droonga/plugins/system/object_count.rb (+1 -1) =================================================================== --- lib/droonga/plugins/system/object_count.rb 2015-04-21 21:47:50 +0900 (40dc304) +++ lib/droonga/plugins/system/object_count.rb 2015-04-21 21:54:22 +0900 (121df31) @@ -46,7 +46,7 @@ module Droonga define_single_step do |step| step.name = "system.object-count" step.handler = ObjectCountHandler - step.collector = Collectors::Sum + step.collector = Collectors::RecursiveSum end end end Modified: lib/droonga/reducer.rb (+14 -0) =================================================================== --- lib/droonga/reducer.rb 2015-04-21 21:47:50 +0900 (1d50b81) +++ lib/droonga/reducer.rb 2015-04-21 21:54:22 +0900 (59894c0) @@ -58,6 +58,10 @@ module Droonga reduced_value = sum(left_value, right_value) reduced_value = self.class.apply_range(reduced_value, "limit" => @deal["limit"]) + when "recursive-sum" + reduced_value = recursive_sum(left_value, right_value) + reduced_value = self.class.apply_range(reduced_value, + "limit" => @deal["limit"]) when "average" reduced_value = (left_value.to_f + right_value.to_f) / 2 when "sort" @@ -77,6 +81,16 @@ module Droonga return x || y if x.nil? or y.nil? if x.is_a?(Hash) and y.is_a?(Hash) + x.merge(y) + else + x + y + end + end + + def recursive_sum(x, y) + return x || y if x.nil? or y.nil? + + if x.is_a?(Hash) and y.is_a?(Hash) if number_hash?(x) and number_hash?(y) sum_number_hashes(x, y) else -------------- next part -------------- HTML����������������������������...Download