Kouhei Sutou 2019-03-04 11:40:46 +0900 (Mon, 04 Mar 2019) Revision: 6f637fff6f356056ff6dcbc9b48c2d53cc7e6c25 https://github.com/groonga/groonga/commit/6f637fff6f356056ff6dcbc9b48c2d53cc7e6c25 Message: expr optimize: add support for option for binary operation For example, threshold for OP_SIMILAR and OP_QUORUM. But binary operation with option is still binary operation...? Should we create a new node class for this case? Modified files: lib/mrb/scripts/expression_tree/binary_operation.rb lib/mrb/scripts/expression_tree_builder.rb Modified: lib/mrb/scripts/expression_tree/binary_operation.rb (+9 -2) =================================================================== --- lib/mrb/scripts/expression_tree/binary_operation.rb 2019-03-04 11:28:13 +0900 (80ad0260a) +++ lib/mrb/scripts/expression_tree/binary_operation.rb 2019-03-04 11:40:46 +0900 (f2dd64e3e) @@ -4,16 +4,23 @@ module Groonga attr_reader :operator attr_reader :left attr_reader :right - def initialize(operator, left, right) + attr_reader :option + def initialize(operator, left, right, option=nil) @operator = operator @left = left @right = right + @option = option end def build(expression) @left.build(expression) @right.build(expression) - expression.append_operator(@operator, 2) + if @option + @option.build(expression) + expression.append_operator(@operator, 3) + else + expression.append_operator(@operator, 2) + end end RANGE_OPERATORS = [ Modified: lib/mrb/scripts/expression_tree_builder.rb (+9 -1) =================================================================== --- lib/mrb/scripts/expression_tree_builder.rb 2019-03-04 11:28:13 +0900 (ed0f75d70) +++ lib/mrb/scripts/expression_tree_builder.rb 2019-03-04 11:40:46 +0900 (1a5f1eb5a) @@ -67,9 +67,17 @@ 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 right = stack.pop left = stack.pop - node = ExpressionTree::BinaryOperation.new(code.op, left, right) + node = ExpressionTree::BinaryOperation.new(code.op, + left, + right, + option) 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/c5f7a9b1/attachment-0001.html>