[Groonga-commit] droonga/fluent-plugin-droonga at d9b8871 [master] Format attributes to an array before joining with sort attributes

Back to archive index

YUKI Hiroshi null+****@clear*****
Thu Nov 28 20:13:10 JST 2013


YUKI Hiroshi	2013-11-28 20:13:10 +0900 (Thu, 28 Nov 2013)

  New Revision: d9b8871f753b622f4db13408c30e5018cb5665a2
  https://github.com/droonga/fluent-plugin-droonga/commit/d9b8871f753b622f4db13408c30e5018cb5665a2

  Message:
    Format attributes to an array before joining with sort attributes

  Modified files:
    lib/droonga/plugin/distributor/search.rb

  Modified: lib/droonga/plugin/distributor/search.rb (+22 -1)
===================================================================
--- lib/droonga/plugin/distributor/search.rb    2013-11-28 20:07:51 +0900 (134562a)
+++ lib/droonga/plugin/distributor/search.rb    2013-11-28 20:13:10 +0900 (4498d9a)
@@ -64,7 +64,7 @@ module Droonga
             # temporarily, for the reducing phase. After all extra columns
             # are removed on the gathering phase.
             final_attributes = collect_output_attributes(output["attributes"])
-            output["attributes"] ||= []
+            output["attributes"] = format_attributes_to_array_style(output["attributes"])
             output["attributes"] += collect_sort_attributes(output["attributes"], query["sortBy"])
  
             elements[element] = sort_reducer(output["attributes"], query["sortBy"])
@@ -172,6 +172,27 @@ module Droonga
       [final_offset, final_limit]
     end
 
+    def format_attributes_to_array_style(attributes)
+      attributes ||= []
+      if attributes.is_a?(Hash)
+        attributes.keys.collect do |key|
+          attribute = attributes[key]
+          case attribute
+          when String
+            {
+              "label": key,
+              "source": attribute,
+            }
+          when Hash
+            attribute["label"] = key
+            attribute
+          end
+        end
+      else
+        attributes
+      end
+    end
+
     def collect_output_attributes(attributes)
       attributes ||= []
       if attributes.is_a?(Hash)
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index