[Groonga-commit] droonga/fluent-plugin-droonga at 574d95c [master] Extract collecting elements code

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Apr 8 18:23:22 JST 2014


Kouhei Sutou	2014-04-08 18:23:22 +0900 (Tue, 08 Apr 2014)

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

  Message:
    Extract collecting elements code

  Modified files:
    lib/droonga/plugins/search.rb

  Modified: lib/droonga/plugins/search.rb (+29 -26)
===================================================================
--- lib/droonga/plugins/search.rb    2014-04-08 18:05:43 +0900 (10bbdc7)
+++ lib/droonga/plugins/search.rb    2014-04-08 18:23:22 +0900 (5ac3241)
@@ -49,32 +49,7 @@ module Droonga
         def collect(message)
           output = message.input || message.name
           if output.is_a?(Hash)
-            elements = output["elements"]
-            if elements and elements.is_a?(Hash)
-              # because "count" mapper requires all records,
-              # I have to apply it at first, before "limit" and "offset" are applied.
-              body = message.body
-              value = message.value
-              count_mapper = elements["count"]
-              if count_mapper
-                if count_mapper["no_output"]
-                  value.delete("count")
-                else
-                  value["count"] = value[count_mapper["target"]].size
-                end
-              end
-
-              records_mapper = elements["records"]
-              if records_mapper and value["records"]
-                if records_mapper["no_output"]
-                  value.delete("records")
-                else
-                  value["records"] = Reducer.apply_range(value["records"],
-                                                         records_mapper)
-                  value["records"] = apply_output_attributes_and_format(value["records"], records_mapper)
-                end
-              end
-            end
+            collect_elements(message, output["elements"])
             output_name = output["output"]
           else
             output_name = output
@@ -83,6 +58,34 @@ module Droonga
         end
 
         private
+        def collect_elements(message, elements)
+          return unless elements.is_a?(Hash)
+
+          # because "count" mapper requires all records,
+          # I have to apply it at first, before "limit" and "offset" are applied.
+          body = message.body
+          value = message.value
+          count_mapper = elements["count"]
+          if count_mapper
+            if count_mapper["no_output"]
+              value.delete("count")
+            else
+              value["count"] = value[count_mapper["target"]].size
+            end
+          end
+
+          records_mapper = elements["records"]
+          if records_mapper and value["records"]
+            if records_mapper["no_output"]
+              value.delete("records")
+            else
+              value["records"] = Reducer.apply_range(value["records"],
+                                                     records_mapper)
+              value["records"] = apply_output_attributes_and_format(value["records"], records_mapper)
+            end
+          end
+        end
+
         def apply_output_attributes_and_format(items, output)
           attributes = output["attributes"] || []
           if output["format"] == "complex"
-------------- next part --------------
HTML����������������������������...
Download 



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