Kouhei Sutou
null+****@clear*****
Tue Apr 9 19:12:03 JST 2013
Kouhei Sutou 2013-04-09 19:12:03 +0900 (Tue, 09 Apr 2013) New Revision: fe66b1c0aeb96467c7ef4eceb5313adbe4480a28 https://github.com/groonga/fluent-plugin-droonga/commit/fe66b1c0aeb96467c7ef4eceb5313adbe4480a28 Message: Extract attributes parameter normalization code Modified files: lib/droonga/plugin/handler_search.rb Modified: lib/droonga/plugin/handler_search.rb (+16 -13) =================================================================== --- lib/droonga/plugin/handler_search.rb 2013-04-09 19:10:52 +0900 (938da09) +++ lib/droonga/plugin/handler_search.rb 2013-04-09 19:12:03 +0900 (8fe2b0a) @@ -223,7 +223,22 @@ module Droonga attributes = params["attributes"] return if attributes.nil? - target_attributes = attributes.map do |attribute| + target_attributes = normalize_target_attributes(attributes) + offset = params["offset"] || 0 + limit = params["limit"] || 10 + @result.open_cursor(:offset => offset, :limit => limit) do |cursor| + formatted_result["records"] = cursor.collect do |record| + values = {} + target_attributes.collect do |attribute| + values[attribute[:label]] = record[attribute[:source]] + end + values + end + end + end + + def normalize_target_attributes(attributes) + attributes.map do |attribute| if attribute.is_a?(String) { label: attribute, @@ -236,18 +251,6 @@ module Droonga } end end - - offset = params["offset"] || 0 - limit = params["limit"] || 10 - @result.open_cursor(:offset => offset, :limit => limit) do |cursor| - formatted_result["records"] = cursor.collect do |record| - values = {} - target_attributes.collect do |attribute| - values[attribute[:label]] = record[attribute[:source]] - end - values - end - end end end end -------------- next part -------------- HTML����������������������������...Download