[Groonga-commit] ranguba/groonga-client at 10ba9d2 [master] Support query_flags

Back to archive index

Kouhei Sutou null+****@clear*****
Mon Aug 21 10:01:39 JST 2017


Kouhei Sutou	2017-08-21 10:01:39 +0900 (Mon, 21 Aug 2017)

  New Revision: 10ba9d2962edf6d03eaf4da083ea567e6463ebb1
  https://github.com/ranguba/groonga-client/commit/10ba9d2962edf6d03eaf4da083ea567e6463ebb1

  Message:
    Support query_flags

  Modified files:
    lib/groonga/client/request/select.rb
    test/request/test-select.rb

  Modified: lib/groonga/client/request/select.rb (+48 -0)
===================================================================
--- lib/groonga/client/request/select.rb    2017-05-31 15:46:38 +0900 (01ad86b)
+++ lib/groonga/client/request/select.rb    2017-08-21 10:01:39 +0900 (c0aaf3c)
@@ -47,6 +47,54 @@ module Groonga
                         RequestParameter.new(:query, value))
         end
 
+        # Sets flags to custom how to parse query.
+        #
+        # @example One flag
+        #    request.
+        #      # Support "COLUMN_NAME:..." syntax
+        #      query_flags("ALLOW_COLUMN").
+        #        # -> --query_flags 'ALLOW_COLUMN'
+        #      query("title:@Groonga")
+        #        # -> --query_flags 'ALLOW_COLUMN'
+        #        #    --query 'title:@Groonga'
+        #
+        # @example Multiple flags
+        #    request.
+        #      # Support "COLUMN_NAME:..." syntax
+        #      # Fallback syntax error query to searchable query
+        #      query_flags(["ALLOW_COLUMN", "QUERY_NO_SYNTAX_ERROR"]).
+        #        # -> --query_flags 'ALLOW_COLUMN'
+        #      query("nonexistent:@Groonga")
+        #        # -> --query_flags 'ALLOW_COLUMN'
+        #        #    --query 'nonexistent:@Groonga'
+        #        # Normally, "nonexistent:@Groonga" is syntax error
+        #        # but it's parsed as
+        #        # "search by one keyword: 'nonexistent:@Groonga'"
+        #        # because QUERY_NO_SYNTAX_ERROR flag is used
+        #
+        # @return [Groonga::Client::Request::Select]
+        #
+        #   The new request with the given flag.
+        #
+        # @overload query_flags(flag)
+        #
+        #   Sets a `#{flag}` flag.
+        #
+        #   @param flag [String] The flag to be used.
+        #
+        #   @since 0.5.0
+        #
+        # @overload query_flags(flags)
+        #
+        #   Sets `#{flag1}|#{flag2}|...` flags.
+        #
+        #   @param flags [::Array<String>] The flags to be used.
+        #
+        #   @since 0.5.0
+        def query_flags(value)
+          flags_parameter(:query_flags, value)
+        end
+
         # Adds a script syntax condition. If the request already has
         # any filter condition, they are combined by AND.
         #

  Modified: test/request/test-select.rb (+22 -0)
===================================================================
--- test/request/test-select.rb    2017-05-31 15:46:38 +0900 (c6d40c2)
+++ test/request/test-select.rb    2017-08-21 10:01:39 +0900 (23a8f17)
@@ -311,4 +311,26 @@ class TestRequestSelect < Test::Unit::TestCase
       end
     end
   end
+
+  sub_test_case("#query_flags") do
+    def query_flags(*args)
+      @request.query_flags(*args).to_parameters
+    end
+
+    test("one") do
+      assert_equal({
+                     :table => "posts",
+                     :query_flags => "ALLOW_COLUMN",
+                   },
+                   query_flags("ALLOW_COLUMN"))
+    end
+
+    test("multiple") do
+      assert_equal({
+                     :table => "posts",
+                     :query_flags => "ALLOW_COLUMN|QUERY_NO_SYNTAX_ERROR",
+                   },
+                   query_flags(["ALLOW_COLUMN", "QUERY_NO_SYNTAX_ERROR"]))
+    end
+  end
 end
-------------- next part --------------
HTML����������������������������...
Download 



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