[Groonga-commit] droonga/fluent-plugin-droonga at 82450c2 [master] Extract ComplexAttributesFormatter

アーカイブの一覧に戻る

Yoji Shidara null+****@clear*****
Thu Jan 23 10:44:13 JST 2014


Yoji Shidara	2014-01-23 10:44:13 +0900 (Thu, 23 Jan 2014)

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

  Merged 1ab6677: Merge branch 'output-attributes'

  Message:
    Extract ComplexAttributesFormatter

  Modified files:
    lib/droonga/searcher.rb

  Modified: lib/droonga/searcher.rb (+39 -32)
===================================================================
--- lib/droonga/searcher.rb    2014-01-23 10:39:48 +0900 (8f8f153)
+++ lib/droonga/searcher.rb    2014-01-23 10:44:13 +0900 (68174ad)
@@ -393,6 +393,43 @@ module Droonga
       end
     end
 
+    class ComplexAttributesFormatter
+      def format_attribute(attribute, table)
+        source = attribute[:source]
+        if source == "_subrecs"
+          sub_record_table = table.range
+          sub_attributes = {}
+          attribute[:attributes].each do |sub_attribute|
+            sub_label = sub_attribute[:label]
+            sub_attributes[sub_label] =
+              format_attribute(sub_attribute, sub_record_table)
+          end
+          {
+            "attributes" => sub_attributes
+          }
+        else
+          expression = attribute[:expression]
+          if expression
+            # TODO implement
+          else
+            column = table.column(source)
+            vector = column.respond_to?(:vector?) ? column.vector? : false
+            {"type" => column.range.name, "vector" => vector}
+          end
+        end
+      end
+
+      def format(attributes, table)
+        formatted_attributes = {}
+        attributes.collect do |attribute|
+          formatted_attribute = format_attribute(attribute, table)
+          attribute_name = attribute[:label]
+          formatted_attributes[attribute_name] = formatted_attribute
+        end
+        formatted_attributes
+      end
+    end
+
     class ResultFormatter
       class << self
         def format(search_request, search_result)
@@ -470,38 +507,8 @@ module Droonga
       end
 
       def format_attributes_complex(attributes)
-        formatted_attributes = {}
-        attributes.collect do |attribute|
-          formatted_attribute = format_attribute_complex(attribute, @result.records)
-          attribute_name = attribute[:label]
-          formatted_attributes[attribute_name] = formatted_attribute
-        end
-        formatted_attributes
-      end
-
-      def format_attribute_complex(attribute, table)
-        source = attribute[:source]
-        if source == "_subrecs"
-          sub_record_table = table.range
-          sub_attributes = {}
-          attribute[:attributes].each do |sub_attribute|
-            sub_label = sub_attribute[:label]
-            sub_attributes[sub_label] =
-              format_attribute_complex(sub_attribute, sub_record_table)
-          end
-          {
-            "attributes" => sub_attributes
-          }
-        else
-          expression = attribute[:expression]
-          if expression
-            # TODO implement
-          else
-            column = table.column(source)
-            vector = column.respond_to?(:vector?) ? column.vector? : false
-            {"type" => column.range.name, "vector" => vector}
-          end
-        end
+        formatter = ComplexAttributesFormatter.new
+        formatter.format(attributes, @result.records)
       end
 
       def format_records
-------------- next part --------------
HTML����������������������������...
ダウンロード 



More information about the Groonga-commit mailing list
アーカイブの一覧に戻る