Kouhei Sutou
null+****@clear*****
Tue Apr 9 18:56:48 JST 2013
Kouhei Sutou 2013-04-09 18:56:48 +0900 (Tue, 09 Apr 2013) New Revision: 635f452b987834de4aa861d7510e45aabe304065 https://github.com/groonga/fluent-plugin-droonga/commit/635f452b987834de4aa861d7510e45aabe304065 Message: Extract formatting records code Modified files: lib/droonga/plugin/handler_search.rb Modified: lib/droonga/plugin/handler_search.rb (+25 -21) =================================================================== --- lib/droonga/plugin/handler_search.rb 2013-04-09 18:56:22 +0900 (46de2ea) +++ lib/droonga/plugin/handler_search.rb 2013-04-09 18:56:48 +0900 (f1c8976) @@ -101,27 +101,7 @@ module Droonga params = @query["output"] formatted_result = {} format_count(params, formatted_result) - offset = params["offset"] || 0 - limit = params["limit"] || 10 - if params["attributes"].is_a? Array - attributes = params["attributes"].map do |attribute| - if attribute.is_a?(String) - { label: attribute, source: attribute} - else - { label: attribute["label"] || attribute["source"], - source: attribute["source"] } - end - end - @result.open_cursor(:offset => offset, :limit => limit) do |cursor| - formatted_result["records"] = cursor.collect do |record| - values = {} - attributes.collect do |attribute| - values[attribute[:label]] = record[attribute[:source]] - end - values - end - end - end + format_records(params, formatted_result) if params["elapsedTime"] formatted_result["startTime"] = @start_time.iso8601 formatted_result["elapsedTime"] = Time.now.to_f - @start_time.to_f @@ -238,6 +218,30 @@ module Droonga return unless params["count"] formatted_result["count"] =****@resul***** end + + def format_records(params, formatted_result) + offset = params["offset"] || 0 + limit = params["limit"] || 10 + if params["attributes"].is_a? Array + attributes = params["attributes"].map do |attribute| + if attribute.is_a?(String) + { label: attribute, source: attribute} + else + { label: attribute["label"] || attribute["source"], + source: attribute["source"] } + end + end + @result.open_cursor(:offset => offset, :limit => limit) do |cursor| + formatted_result["records"] = cursor.collect do |record| + values = {} + attributes.collect do |attribute| + values[attribute[:label]] = record[attribute[:source]] + end + values + end + end + end + end end end end -------------- next part -------------- HTML����������������������������... Download