[Groonga-commit] groonga/fluent-plugin-droonga at f1e084b [master] adapter_select: support match_columns and query parameters of select request

Back to archive index

Kosuke Asami null+****@clear*****
Tue Jul 23 16:10:30 JST 2013


Kosuke Asami	2013-07-23 16:10:30 +0900 (Tue, 23 Jul 2013)

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

  Message:
    adapter_select: support match_columns and query parameters of select request
    
    TODO:
    Support multiple match columns

  Modified files:
    lib/droonga/plugin/adapter/groonga/select.rb
    test/plugin/adapter/groonga/test_select.rb

  Modified: lib/droonga/plugin/adapter/groonga/select.rb (+15 -1)
===================================================================
--- lib/droonga/plugin/adapter/groonga/select.rb    2013-07-23 15:30:27 +0900 (5b49c5c)
+++ lib/droonga/plugin/adapter/groonga/select.rb    2013-07-23 16:10:30 +0900 (8bef717)
@@ -18,10 +18,13 @@ module Droonga
     class Select
       def convert_request(select_request)
         table = select_request["table"]
+        match_columns = select_request["match_columns"]
+        match_to = match_columns ? match_columns.split(/ *\|\| */) : []
+        query = select_request["query"]
         output_columns = select_request["output_columns"]
         attributes = output_columns.split(/, */)
 
-        {
+        search_request = {
           "queries" => {
             table => {
               "source" => table,
@@ -38,6 +41,17 @@ module Droonga
             }
           }
         }
+        if query
+          condition = {
+            "query"  => query,
+            "matchTo"=> match_to,
+            "defaultOperator"=> "&&",
+            "allowPragma"=> false,
+            "allowColumn"=> true,
+          }
+          search_request["queries"][table]["condition"] = condition
+        end
+        search_request
       end
 
       def convert_response(search_response)

  Modified: test/plugin/adapter/groonga/test_select.rb (+37 -0)
===================================================================
--- test/plugin/adapter/groonga/test_select.rb    2013-07-23 15:30:27 +0900 (64d84bc)
+++ test/plugin/adapter/groonga/test_select.rb    2013-07-23 16:10:30 +0900 (b11247a)
@@ -94,6 +94,43 @@ class AdapterGroongaSelectTest < Test::Unit::TestCase
         end
       end
     end
+
+    class MatchColumnsTest < self
+      def test_single_column
+        select_request = {
+          "table"          => "EmptyTable",
+          "match_columns"  => "_key",
+          "query"          => "QueryTest",
+          "output_columns" => "_id",
+        }
+
+        expected_search_request = {
+          "queries" => {
+            "EmptyTable" => {
+              "source"   => "EmptyTable",
+              "condition"=> {
+                "query"  => "QueryTest",
+                "matchTo"=> ["_key"],
+                "defaultOperator"=> "&&",
+                "allowPragma"=> false,
+                "allowColumn"=> true,
+              },
+              "output"   => {
+                "elements"   => [
+                  "startTime",
+                  "elapsedTime",
+                  "count",
+                  "attributes",
+                  "records",
+                ],
+                "attributes" => ["_id"],
+              },
+            },
+          },
+        }
+        assert_equal(expected_search_request, convert(select_request))
+      end
+    end
   end
 
   class ResponseTest < self
-------------- next part --------------
HTML����������������������������...
Download 



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