[Groonga-commit] droonga/fluent-plugin-droonga at 4200503 [master] Accept rich operators by the collector

Back to archive index

YUKI Hiroshi null+****@clear*****
Thu Nov 28 16:04:29 JST 2013


YUKI Hiroshi	2013-11-28 16:04:29 +0900 (Thu, 28 Nov 2013)

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

  Message:
    Accept rich operators by the collector

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

  Modified: lib/droonga/plugin/collector/basic.rb (+16 -8)
===================================================================
--- lib/droonga/plugin/collector/basic.rb    2013-11-28 15:50:27 +0900 (3e64c86)
+++ lib/droonga/plugin/collector/basic.rb    2013-11-28 16:04:29 +0900 (367a236)
@@ -99,7 +99,7 @@ module Droonga
         when "sum"
           reduced_values = values[0][key] + values[1][key]
         when "sort"
-          reduced_values = merge(values[0][key], values[1][key], deal["order"])
+          reduced_values = merge(values[0][key], values[1][key], deal["operators"])
         end
 
         reduced_values = apply_output_range(reduced_values, "limit" => deal["limit"])
@@ -109,13 +109,21 @@ module Droonga
       return result
     end
 
-    def merge(x, y, order)
+    def merge(x, y, operators)
+      # normalize operators at first!
+      operators = operators.collect do |operator|
+        if operator.is_a?(String)
+          { "operator" => operator }
+        else
+          operators
+        end
+      end
       index = 0
       y.each do |_y|
         loop do
           _x = x[index]
           break unless _x
-          break if compare(_y, _x, order)
+          break if compare(_y, _x, operators)
           index += 1
         end
         x.insert(index, _y)
@@ -125,11 +133,11 @@ module Droonga
     end
 
     def compare(x, y, operators)
-      for index in 0..x.size-1 do
-        _x = x[index]
-        _y = y[index]
-        operator = operators[index]
-        break unless operator
+      operators.each_with_index do |operator, index|
+        column = operator["column"] || index
+        operator = operator["operator"]
+        _x = x[column]
+        _y = y[column]
         return true if _x.__send__(operator, _y)
       end
       return false

  Modified: lib/droonga/plugin/distributor/search.rb (+16 -8)
===================================================================
--- lib/droonga/plugin/distributor/search.rb    2013-11-28 15:50:27 +0900 (de93a6a)
+++ lib/droonga/plugin/distributor/search.rb    2013-11-28 16:04:29 +0900 (746f2db)
@@ -202,21 +202,29 @@ module Droonga
       sort_attributes      
     end
 
+    ASCENDING_OPERATOR = "<".freeze
+    DESCENDING_OPERATOR = ">".freeze
+
     def sort_reducer(attributes, sort_keys)
+      attributes ||= []
       sort_keys ||= []
       sort_keys = sort_keys["keys"] || [] if sort_keys.is_a?(Hash)
 
-      order = []
-#      unless sort_keys
-        order << "<"
-#      else
-#        # XXX NOT IMPLEMENTED YET!
-#        # we must change the format of "order" from array to hash (rich object)
-#      end
+      operators = sort_keys.collect do |sort_key|
+        operator = ASCENDING_OPERATOR
+        if sort_key[0] == "-"
+          operator = DESCENDING_OPERATOR
+          sort_key = sort_key[1..-1]
+        end
+        {
+          "operator" => operator,
+          "column" => attributes.index(sort_key),
+        }
+      end
 
       {
         "type" => "sort",
-        "order" => order,
+        "operators" => operators,
       }
     end
   end
-------------- next part --------------
HTML����������������������������...
Download 



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