[Groonga-commit] groonga/fluent-plugin-droonga [master] Set output out of searcher

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Apr 9 18:20:07 JST 2013


Kouhei Sutou	2013-04-09 18:20:07 +0900 (Tue, 09 Apr 2013)

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

  Message:
    Set output out of searcher
    
    Now, searcher doesn't need to know result name.

  Modified files:
    lib/droonga/plugin/handler_search.rb

  Modified: lib/droonga/plugin/handler_search.rb (+12 -8)
===================================================================
--- lib/droonga/plugin/handler_search.rb    2013-04-09 18:17:00 +0900 (8c1a938)
+++ lib/droonga/plugin/handler_search.rb    2013-04-09 18:20:07 +0900 (6187ddf)
@@ -48,9 +48,9 @@ module Droonga
       results = {}
       query_sorter.tsort.each do |name|
         if queries[name]
-          searcher = QuerySearcher.new(@context, name, queries[name])
+          searcher = QuerySearcher.new(@context, queries[name])
           results[name] = searcher.search(results)
-          searcher.output(outputs)
+          outputs[name] = searcher.output if searcher.need_output?
         elsif @context[name]
           results[name] = @context[name]
         else
@@ -82,9 +82,8 @@ module Droonga
     end
 
     class QuerySearcher
-      def initialize(context, name, query)
+      def initialize(context, query)
         @context = context
-        @name = name
         @query = query
         @result = nil
       end
@@ -198,13 +197,18 @@ module Droonga
         result
       end
 
-      def output(outputs)
+      def need_output?
+        @query.has_key?("output")
+      end
+
+      def output
+        return nil unless need_output?
+
         query = @query
         result = @result
-        if query["output"]
+        output = {}
           offset = query["output"]["offset"] || 0
           limit = query["output"]["limit"] || 10
-          outputs[@name] = output = {}
           if query["output"]["count"]
             count = result.size
             output["count"] = count
@@ -233,7 +237,7 @@ module Droonga
             output["startTime"] = start_time.iso8601
             output["elapsedTime"] = Time.now.to_f - start_time.to_f
           end
-        end
+        output
       end
     end
   end
-------------- next part --------------
HTML����������������������������...
Download 



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