[Groonga-commit] groonga/groonga at acb3977 [master] expr optimize: add support for weighted match

Back to archive index
Kouhei Sutou null+****@clear*****
Mon Mar 4 15:07:01 JST 2019


Kouhei Sutou	2019-03-04 15:07:01 +0900 (Mon, 04 Mar 2019)

  Revision: acb39770a37421db9723512f0eac7c1107a34961
  https://github.com/groonga/groonga/commit/acb39770a37421db9723512f0eac7c1107a34961

  Message:
    expr optimize: add support for weighted match

  Modified files:
    lib/mrb/scripts/expression_rewriters/optimizer.rb
    lib/mrb/scripts/expression_tree/binary_operation.rb
    lib/mrb/scripts/expression_tree_builder.rb

  Modified: lib/mrb/scripts/expression_rewriters/optimizer.rb (+7 -7)
===================================================================
--- lib/mrb/scripts/expression_rewriters/optimizer.rb    2019-03-04 14:55:55 +0900 (46115fc2f)
+++ lib/mrb/scripts/expression_rewriters/optimizer.rb    2019-03-04 15:07:01 +0900 (6417d4bbd)
@@ -96,11 +96,11 @@ module Groonga
       def optimize_binary_operation_node(table, node)
         optimized_left = optimize_node(table, node.left)
         optimized_right = optimize_node(table, node.right)
-        if node.option
-          optimized_option = optimize_node(table, node.option)
-        else
-          optimized_option = nil
+        optimized_options = {}
+        if node.parameter
+          optimized_options[:parameter] = optimize_node(table, node.parameter)
         end
+        optimized_options[:value] = node.value
         case node.operator
         when Operator::EQUAL
           if optimized_left.is_a?(ExpressionTree::Constant) and
@@ -108,18 +108,18 @@ module Groonga
             ExpressionTree::BinaryOperation.new(node.operator,
                                                 optimized_right,
                                                 optimized_left,
-                                                optimized_option)
+                                                optimized_options)
           else
             ExpressionTree::BinaryOperation.new(node.operator,
                                                 optimized_left,
                                                 optimized_right,
-                                                optimized_option)
+                                                optimized_options)
           end
         else
           ExpressionTree::BinaryOperation.new(node.operator,
                                               optimized_left,
                                               optimized_right,
-                                              optimized_option)
+                                              optimized_options)
         end
       end
 

  Modified: lib/mrb/scripts/expression_tree/binary_operation.rb (+13 -7)
===================================================================
--- lib/mrb/scripts/expression_tree/binary_operation.rb    2019-03-04 14:55:55 +0900 (bceece427)
+++ lib/mrb/scripts/expression_tree/binary_operation.rb    2019-03-04 15:07:01 +0900 (dab59341c)
@@ -4,22 +4,28 @@ module Groonga
       attr_reader :operator
       attr_reader :left
       attr_reader :right
-      attr_reader :option
-      def initialize(operator, left, right, option=nil)
+      attr_reader :parameter
+      attr_reader :value
+      def initialize(operator, left, right, options={})
         @operator = operator
         @left = left
         @right = right
-        @option = option
+        @parameter = options[:parameter]
+        @value = options[:value]
       end
 
       def build(expression)
         @left.build(expression)
         @right.build(expression)
-        if @option
-          @option.build(expression)
-          expression.append_operator(@operator, 3)
+        n_args = 2
+        if @parameter
+          @parameter.build(expression)
+          n_args += 1
+        end
+        if @value
+          expression.append_constant(@value, @operator, n_args)
         else
-          expression.append_operator(@operator, 2)
+          expression.append_operator(@operator, n_args)
         end
       end
 

  Modified: lib/mrb/scripts/expression_tree_builder.rb (+4 -6)
===================================================================
--- lib/mrb/scripts/expression_tree_builder.rb    2019-03-04 14:55:55 +0900 (3daa8b350)
+++ lib/mrb/scripts/expression_tree_builder.rb    2019-03-04 15:07:01 +0900 (02285d761)
@@ -67,17 +67,15 @@ module Groonga
           node = ExpressionTree::LogicalOperation.new(code.op, nodes)
           stack.push(node)
         when *RELATION_OPERATORS, *ARITHMETIC_OPERATORS
-          if code.n_args == 3
-            option = stack.pop
-          else
-            option = nil
-          end
+          options = {}
+          options[:parameter] = stack.pop if code.n_args == 3
+          options[:value] = code.value.value if code.value
           right = stack.pop
           left = stack.pop
           node = ExpressionTree::BinaryOperation.new(code.op,
                                                      left,
                                                      right,
-                                                     option)
+                                                     options)
           stack.push(node)
         when *UNARY_OPERATIONS
           value = stack.pop
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20190304/3845d5c6/attachment-0001.html>


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