[Groonga-commit] ranguba/rroonga at 3cec5bc [master] Support call expression

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Oct 6 16:47:34 JST 2015


Kouhei Sutou	2015-10-06 16:47:34 +0900 (Tue, 06 Oct 2015)

  New Revision: 3cec5bcc7f5d23b696facedadfce9e963f0cb95b
  https://github.com/ranguba/rroonga/commit/3cec5bcc7f5d23b696facedadfce9e963f0cb95b

  Message:
    Support call expression

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

  Modified: lib/groonga/expression-builder.rb (+27 -1)
===================================================================
--- lib/groonga/expression-builder.rb    2015-10-06 13:43:52 +0900 (f563236)
+++ lib/groonga/expression-builder.rb    2015-10-06 16:47:34 +0900 (712efd5)
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 #
 # Copyright (C) 2015  Masafumi Yokoyama <yokoyama �� clear-code.com>
-# Copyright (C) 2009-2012  Kouhei Sutou <kou �� clear-code.com>
+# Copyright (C) 2009-2015  Kouhei Sutou <kou �� clear-code.com>
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -448,6 +448,28 @@ module Groonga
         super(Groonga::Operation::TERM_EXTRACT, column_value_builder, value)
       end
     end
+
+    # @private
+    class CallExpressionBuilder < ExpressionBuilder
+      def initialize(function, *arguments)
+        super()
+        @function = function
+        @arguments = arguments
+      end
+
+      def build(expression, variable)
+        expression.append_object(@function)
+        @arguments.each do |argument|
+          case argument
+          when String
+            expression.append_constant(argument)
+          else
+            argument.build(expression, variable)
+          end
+        end
+        expression.append_operation(Operation::CALL, @arguments.size)
+      end
+    end
   end
 
   # @private
@@ -516,6 +538,10 @@ module Groonga
       column_expression_builder(object, name)
     end
 
+    def call(function, *arguments)
+      CallExpressionBuilder.new(@table.context[function], *arguments)
+    end
+
     private
     def build_match_target(&block)
       sub_builder = MatchTargetRecordExpressionBuilder.new(@table, nil)

  Modified: test/test-expression-builder.rb (+38 -1)
===================================================================
--- test/test-expression-builder.rb    2015-10-06 13:43:52 +0900 (14e74dc)
+++ test/test-expression-builder.rb    2015-10-06 16:47:34 +0900 (93b7d3a)
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 #
 # Copyright (C) 2014-2015  Masafumi Yokoyama <yokoyama �� clear-code.com>
-# Copyright (C) 2009-2012  Kouhei Sutou <kou �� clear-code.com>
+# Copyright (C) 2009-2015  Kouhei Sutou <kou �� clear-code.com>
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -523,6 +523,43 @@ EOC
     end
   end
 
+  class CallTest < self
+    def setup_tables
+      Groonga::Schema.define do |schema|
+        schema.create_table("Shops",
+                            :type => :hash,
+                            :key_type => "ShortText") do |table|
+          table.wgs84_geo_point("location")
+        end
+
+        schema.create_table("Locations",
+                            :type => :patricia_trie,
+                            :key_type => :wgs84_geo_point) do |table|
+          table.index("Shops.location")
+        end
+      end
+
+      @shops = Groonga["Shops"]
+    end
+
+    def setup_data
+      @shops.add("Nezu no taiyaki", :location => "35.720253,139.762573")
+      @shops.add("Taiyaki Kataoka", :location => "35.712521,139.715591")
+      @shops.add("Taiyaki Sharaku", :location => "35.716969,139.794846")
+    end
+
+    def test_search
+      result =****@shops***** do |record|
+        record.call("geo_in_rectangle",
+                    record.location,
+                    "35.7185,139.7912",
+                    "35.7065,139.8069")
+      end
+      assert_equal(["Taiyaki Sharaku"],
+                   result.collect(&:_key))
+    end
+  end
+
   class RecordTest < self
     def setup_tables
       Groonga::Schema.define do |schema|
-------------- next part --------------
HTML����������������������������...
Download 



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