[Groonga-commit] droonga/fluent-plugin-droonga at 1bf359e [master] Sort unified items

Back to archive index

YUKI Hiroshi null+****@clear*****
Wed Dec 4 14:18:27 JST 2013


YUKI Hiroshi	2013-12-04 14:18:27 +0900 (Wed, 04 Dec 2013)

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

  Message:
    Sort unified items

  Modified files:
    lib/droonga/plugin/collector/basic.rb

  Modified: lib/droonga/plugin/collector/basic.rb (+20 -9)
===================================================================
--- lib/droonga/plugin/collector/basic.rb    2013-12-04 13:59:42 +0900 (1439fea)
+++ lib/droonga/plugin/collector/basic.rb    2013-12-04 14:18:27 +0900 (18bbcd7)
@@ -108,15 +108,7 @@ module Droonga
     end
 
     def merge(x, y, options={})
-      # Normalize operators at first for optimization.
-      operators = options[:operators] || []
-      operators = operators.collect do |operator|
-        if operator.is_a?(String)
-          { "operator" => operator }
-        else
-          operator
-        end
-      end
+      operators = options[:operators] = normalize_operators(options[:operators])
 
       unify_by_key!(x, y, options)
 
@@ -134,6 +126,17 @@ module Droonga
       return x
     end
 
+    def normalize_operators(operators)
+      operators ||= []
+      operators.collect do |operator|
+        if operator.is_a?(String)
+          { "operator" => operator }
+        else
+          operator
+        end
+      end
+    end
+
     def compare(x, y, operators)
       operators.each_with_index do |operator, index|
         column = operator["column"] || index
@@ -175,6 +178,14 @@ module Droonga
           end
         end
       end
+
+      unified_items.sort! do |a, b|
+        if compare(a, b, options[:operators])
+          -1
+        else
+          1
+        end
+      end
     end
   end
 end
-------------- next part --------------
HTML����������������������������...
Descargar 



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