[Groonga-commit] droonga/fluent-plugin-droonga at 120c566 [master] Add per output logic to Proxy.

Zurück zum Archiv-Index

Daijiro MORI null+****@clear*****
Sat Aug 17 16:00:00 JST 2013


Daijiro MORI	2013-08-17 16:00:00 +0900 (Sat, 17 Aug 2013)

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

  Message:
    Add per output logic to Proxy.

  Modified files:
    lib/droonga/plugin/handler_proxy.rb
    lib/droonga/proxy.rb

  Modified: lib/droonga/plugin/handler_proxy.rb (+18 -7)
===================================================================
--- lib/droonga/plugin/handler_proxy.rb    2013-08-17 13:37:36 +0900 (1bbd93d)
+++ lib/droonga/plugin/handler_proxy.rb    2013-08-17 16:00:00 +0900 (4a28535)
@@ -25,21 +25,32 @@ module Droonga
     command :proxy_search
     def proxy_search(request)
       searcher = Droonga::Searcher.new(@context)
-      searcher.search(args)
+      searcher.search(body).each do |output, value|
+        emit(value, output)
+      end
     end
 
     command :proxy_gather
     def proxy_gather(request)
-      request.flatten
+      output = body ? body[name] : name
+      emit(request, output)
     end
 
     command :proxy_reduce
     def proxy_reduce(request)
-      a, b = request
-      a ||= {}
-      a[name] ||= []
-      a[name] << b
-      a
+      output = outputs.first
+      a = values[output]
+      b = request
+      return unless b
+      unless a
+        emit b
+        return
+      end
+      a.each do |key, value|
+        next unless b[key]
+        a[key] = value + b[key]
+      end
+      emit(a, output)
     end
   end
 end

  Modified: lib/droonga/proxy.rb (+20 -8)
===================================================================
--- lib/droonga/proxy.rb    2013-08-17 13:37:36 +0900 (3f2042e)
+++ lib/droonga/proxy.rb    2013-08-17 16:00:00 +0900 (9e15477)
@@ -165,7 +165,7 @@ module Droonga
               "route" => route,
               "component" => component,
               "n_of_inputs" => 0,
-              "value" => nil
+              "values" => {}
             }
             tasks << task
             (component["inputs"] || [nil]).each do |input|
@@ -251,14 +251,14 @@ module Droonga
           end
           return if task["n_of_inputs"] < component["n_of_expects"]
           #the task is done
-          result = task["value"]
+          result = task["values"]
           post = component["post"]
           @proxy.post(result, post) if post
           component["descendants"].each do |name, indices|
             message = {
               "id" => @id,
               "input" => name,
-              "value" => result
+              "value" => result[name]
             }
             indices.each do |index|
               dest = @components[index]
@@ -293,15 +293,27 @@ module Droonga
   end
 
   class ProxyHandler < Droonga::Handler
-    attr_reader :task, :name, :component, :args
+    attr_reader :task, :name, :component, :values, :body, :outputs
     def handle(command, request, *arguments)
       @task = request["task"]
       @name = request["name"]
       @component = @task["component"]
-      @args = @component["args"]
-      value0 = @task["value"]
-      value1 = request["value"]
-      @task["value"] = super(command, [value0, value1], *arguments)
+      @outputs = @component["outputs"]
+      @body = @component["body"]
+      @values = @task["values"]
+      super(command, request["value"], *arguments)
+    end
+
+    def emit(value, name = nil)
+      unless name
+        if component["outputs"]
+          name = component["outputs"].first
+        else
+          @task["values"] = value
+          return
+        end
+      end
+      @task["values"][name] = value
     end
 
     def prefer_synchronous?(command)
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Zurück zum Archiv-Index