[Groonga-commit] groonga/fluent-plugin-droonga [master] Support "query" and "matchTo" parameters

Back to archive index

Daijiro MORI null+****@clear*****
Sat Mar 30 13:43:29 JST 2013


Daijiro MORI	2013-03-30 13:43:29 +0900 (Sat, 30 Mar 2013)

  New Revision: 1271fe765610826843f4df5962b3f0ebc2a7546e
  https://github.com/groonga/fluent-plugin-droonga/commit/1271fe765610826843f4df5962b3f0ebc2a7546e

  Message:
    Support "query" and "matchTo" parameters

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

  Modified: lib/droonga/plugin/handler_search.rb (+18 -2)
===================================================================
--- lib/droonga/plugin/handler_search.rb    2013-03-29 17:24:22 +0900 (8e34e7a)
+++ lib/droonga/plugin/handler_search.rb    2013-03-30 13:43:29 +0900 (7b32de8)
@@ -49,7 +49,23 @@ module Droonga
       start_time = Time.now
       query = queries[name]
       source = results[query["source"]]
+      if query["query"]
+        options = query["options"] || {}
+        if query["matchTo"]
+          matchTo = Groonga::Expression.new(context: @context)
+          matchTo.define_variable(:domain => source)
+          matchTo.parse(query["matchTo"], :syntax => :script)
+          options[:default_column] = matchTo
+        end
+        query_expression = Groonga::Expression.new(context: @context)
+        query_expression.define_variable(:domain => source)
+        query_expression.parse(query["query"], options)
+        results[name] = source.select(query_expression)
+      else
+        results[name] = source
+      end
       if query["output"]
+        result = results[name]
         offset = query["offset"] || 0
         limit = query["limit"] || 10
         columns = source.columns
@@ -61,7 +77,7 @@ module Droonga
           }
         end
         column_names = columns.collect(&:local_name)
-        records = source.open_cursor(:offset => offset,
+        records = result.open_cursor(:offset => offset,
                                      :limit => limit) do |cursor|
           cursor.collect do |record|
             column_names.collect do |name|
@@ -71,7 +87,7 @@ module Droonga
         end
         elapsed_time = Time.now.to_f - start_time.to_f
         outputs[name] = {
-          "count" => source.size,
+          "count" => result.size,
           "startTime" => start_time.iso8601,
           "elapsedTime" => elapsed_time,
           "attributes" => attributes,
-------------- next part --------------
HTML����������������������������...
Download 



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