YUKI Hiroshi
null+****@clear*****
Thu Nov 28 13:50:15 JST 2013
YUKI Hiroshi 2013-11-28 13:50:15 +0900 (Thu, 28 Nov 2013) New Revision: c957bdc88926a951748f6241336114777bbaeea4 https://github.com/droonga/fluent-plugin-droonga/commit/c957bdc88926a951748f6241336114777bbaeea4 Message: Apply final limit and offset on the gathering phase instead of reducing phase Modified files: lib/droonga/plugin/collector/basic.rb lib/droonga/plugin/distributor/search.rb Modified: lib/droonga/plugin/collector/basic.rb (+17 -15) =================================================================== --- lib/droonga/plugin/collector/basic.rb 2013-11-28 13:35:50 +0900 (098b8e3) +++ lib/droonga/plugin/collector/basic.rb 2013-11-28 13:50:15 +0900 (f2725af) @@ -21,10 +21,25 @@ module Droonga class BasicCollector < Droonga::CollectorPlugin repository.register("basic", self) + UNLIMITED = -1 + command :collector_gather - def collector_gather(request) + def collector_gather(result) output = body ? body[input_name] : input_name - emit(request, output) + if output.is_a?(Hash) + element = output["element"] + if element && result[element] && result[element].is_a?(Array) + offset = output["offset"] || 0 + result[element] = result[element][offset..-1] + + limit = output["limit"] || 0 + unless limit == UNLIMITED + result[element] = result[element][0...limit] + end + end + output = output["source"] + end + emit(result, output) end command :collector_reduce @@ -42,30 +57,17 @@ module Droonga result = {} elements.each do |key, deal| reduced_values = nil - case deal["type"] when "sum" reduced_values = values[0][key] + values[1][key] when "sort" reduced_values = merge(values[0][key], values[1][key], deal["order"]) end - - if reduced_values.is_a?(Array) - if deal["offset"] - reduced_values = reduced_values[deal["offset"]..-1] - end - if deal["limit"] && deal["limit"] != UNLIMITED - reduced_values = reduced_values[0...deal["limit"]] - end - end - result[key] = reduced_values end return result end - UNLIMITED = -1 - def merge(x, y, order) index = 0 y.each do |_y| Modified: lib/droonga/plugin/distributor/search.rb (+1 -0) =================================================================== --- lib/droonga/plugin/distributor/search.rb 2013-11-28 13:35:50 +0900 (ddef1e4) +++ lib/droonga/plugin/distributor/search.rb 2013-11-28 13:50:15 +0900 (4afd38a) @@ -52,6 +52,7 @@ module Droonga # TODO: must take "sortBy" section into account. elements[element] = sort_reducer(:attributes => query["attributes"], :sort_keys => query["sortBy"]) + output_mapper[output_name]["element"] = element output_mapper[output_name]["offset"] = final_offset output_mapper[output_name]["limit"] = final_limit end -------------- next part -------------- HTML����������������������������...Download