[Groonga-commit] droonga/droonga-engine at e29c2bd [master] Support "query_flags" parameter for Groonga's "select" command (partially)

Zurück zum Archiv-Index

SHIMODA Piro Hiroshi null+****@clear*****
Mon Oct 6 18:35:18 JST 2014


SHIMODA "Piro" Hiroshi	2014-10-06 18:35:18 +0900 (Mon, 06 Oct 2014)

  New Revision: e29c2bd6be2afe7e39cd5801fcd8a95af9dd9dfa
  https://github.com/droonga/droonga-engine/commit/e29c2bd6be2afe7e39cd5801fcd8a95af9dd9dfa

  Message:
    Support "query_flags" parameter for Groonga's "select" command (partially)
    
    Currently, only these flags are avaiable: ALLOW_PRAGMA, ALLOW_COLUMN, and NONE.
    
    And, allowPragma becomes true by default by the spec of Groonga's select command.
    See: http://groonga.org/ja/docs/reference/commands/select.html#query-flags

  Modified files:
    lib/droonga/plugins/groonga/select.rb
    test/unit/plugins/groonga/select/test_adapter_input.rb

  Modified: lib/droonga/plugins/groonga/select.rb (+14 -3)
===================================================================
--- lib/droonga/plugins/groonga/select.rb    2014-10-06 17:58:58 +0900 (73f35af)
+++ lib/droonga/plugins/groonga/select.rb    2014-10-06 18:35:18 +0900 (b5f4cf3)
@@ -19,6 +19,7 @@ module Droonga
   module Plugins
     module Groonga
       module Select
+        DEFAULT_QUERY_FLAGS = "ALLOW_PRAGMA|ALLOW_COLUMN"
         DRILLDOWN_RESULT_PREFIX = "drilldown_result_"
 
         class RequestConverter
@@ -89,13 +90,13 @@ module Droonga
 
             conditions = []
             if query
-              conditions << {
+              condition = {
                 "query"  => query,
                 "matchTo"=> match_to,
                 "defaultOperator"=> "&&",
-                "allowPragma"=> false,
-                "allowColumn"=> true,
               }
+              apply_query_flags(condition, select_request["query_flags"])
+              conditions << condition
             end
 
             if filter
@@ -114,6 +115,16 @@ module Droonga
             condition
           end
 
+          def apply_query_flags(condition, flags)
+            flags ||= DEFAULT_QUERY_FLAGS
+            flags = flags.split("|")
+            condition["allowPragma"] = flags.include?("ALLOW_PRAGMA")
+            condition["allowColumn"] = flags.include?("ALLOW_COLUMN")
+            #XXX not supported yet by the "search" command
+            # condition["allowUpdate"] = flags.include?("ALLOW_UPDATE")
+            # condition["allowLeadingNot"] = flags.include?("ALLOW_LEADING_NOT")
+          end
+
           def convert_drilldown(select_request)
             drilldown_keys = select_request["drilldown"]
             return nil if drilldown_keys.nil? or drilldown_keys.empty?

  Modified: test/unit/plugins/groonga/select/test_adapter_input.rb (+56 -0)
===================================================================
--- test/unit/plugins/groonga/select/test_adapter_input.rb    2014-10-06 17:58:58 +0900 (fc87875)
+++ test/unit/plugins/groonga/select/test_adapter_input.rb    2014-10-06 18:35:18 +0900 (4b0d1d1)
@@ -189,6 +189,62 @@ class GroongaSelectAdapterInputTest < Test::Unit::TestCase
     end
   end
 
+  class QueryFlagsTest < self
+    def test_none
+      select_request = {
+        "table"          => "EmptyTable",
+        "match_columns"  => "_key",
+        "query"          => "QueryTest",
+        "query_flags"    => "NONE",
+      }
+      expected_search_condition = {
+        "query"  => "QueryTest",
+        "matchTo"=> ["_key"],
+        "defaultOperator"=> "&&",
+        "allowPragma" => false,
+        "allowColumn" => false,
+      }
+      assert_equal(expected_search_condition,
+                   convert(select_request)["queries"]["EmptyTable_result"]["condition"])
+    end
+
+    def test_allow_pragma_only
+      select_request = {
+        "table"          => "EmptyTable",
+        "match_columns"  => "_key",
+        "query"          => "QueryTest",
+        "query_flags"    => "ALLOW_PRAGMA",
+      }
+      expected_search_condition = {
+        "query"  => "QueryTest",
+        "matchTo"=> ["_key"],
+        "defaultOperator"=> "&&",
+        "allowPragma" => true,
+        "allowColumn" => false,
+      }
+      assert_equal(expected_search_condition,
+                   convert(select_request)["queries"]["EmptyTable_result"]["condition"])
+    end
+
+    def test_allow_column_only
+      select_request = {
+        "table"          => "EmptyTable",
+        "match_columns"  => "_key",
+        "query"          => "QueryTest",
+        "query_flags"    => "ALLOW_COLUMN",
+      }
+      expected_search_condition = {
+        "query"  => "QueryTest",
+        "matchTo"=> ["_key"],
+        "defaultOperator"=> "&&",
+        "allowPragma" => false,
+        "allowColumn" => true,
+      }
+      assert_equal(expected_search_condition,
+                   convert(select_request)["queries"]["EmptyTable_result"]["condition"])
+    end
+  end
+
   class OffsetTest < self
     def assert_offset(expected_offset, offset)
       select_request = {
-------------- next part --------------
HTML����������������������������...
Download 



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