[Groonga-commit] ranguba/rroonga at ca273a1 [master] Support AND_NOT

Back to archive index

Kouhei Sutou null+****@clear*****
Sun Feb 21 00:21:08 JST 2016


Kouhei Sutou	2016-02-21 00:21:08 +0900 (Sun, 21 Feb 2016)

  New Revision: ca273a16bf59e2bc1021f9223b4b9a8e7c00e155
  https://github.com/ranguba/rroonga/commit/ca273a16bf59e2bc1021f9223b4b9a8e7c00e155

  Message:
    Support AND_NOT

  Modified files:
    lib/groonga/expression-builder.rb
    test/test-expression-builder.rb

  Modified: lib/groonga/expression-builder.rb (+15 -0)
===================================================================
--- lib/groonga/expression-builder.rb    2016-01-18 19:16:27 +0900 (191c57c)
+++ lib/groonga/expression-builder.rb    2016-02-21 00:21:08 +0900 (504a394)
@@ -56,6 +56,10 @@ module Groonga
       other
     end
 
+    def -(other)
+      other
+    end
+
     private
     def default_parse_options
       {
@@ -110,6 +114,10 @@ module Groonga
       def |(other)
         OrExpressionBuilder.new(self, other)
       end
+
+      def -(other)
+        AndNotExpressionBuilder.new(self, other)
+      end
     end
 
     # @private
@@ -144,6 +152,13 @@ module Groonga
     end
 
     # @private
+    class AndNotExpressionBuilder < SetExpressionBuilder
+      def initialize(*expression_builders)
+        super(Groonga::Operation::AND_NOT, *expression_builders)
+      end
+    end
+
+    # @private
     class ColumnValueExpressionBuilder < ExpressionBuilder
       def initialize(column, options={})
         super()

  Modified: test/test-expression-builder.rb (+8 -0)
===================================================================
--- test/test-expression-builder.rb    2016-01-18 19:16:27 +0900 (93b7d3a)
+++ test/test-expression-builder.rb    2016-02-21 00:21:08 +0900 (fc7de26)
@@ -195,6 +195,14 @@ class ExpressionBuilderTest < Test::Unit::TestCase
       assert_equal(["gunyara-kun", "yu"],
                    result.collect {|record| record.key.key})
     end
+
+    def test_and_not
+      result =****@users***** do |record|
+        (record["hp"] > 100) - (record["hp"] == 150)
+      end
+      assert_equal(["yu"],
+                   result.collect {|record| record.key.key})
+    end
   end
 
   class FullTextSearchTest < self
-------------- next part --------------
HTML����������������������������...
Download 



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