Kouhei Sutou
null+****@clear*****
Mon Feb 23 14:57:14 JST 2015
Kouhei Sutou 2015-02-23 14:57:14 +0900 (Mon, 23 Feb 2015) New Revision: 71e16eb56a903de07171b796d96cfd720ec45f0c https://github.com/groonga/groonga/commit/71e16eb56a903de07171b796d96cfd720ec45f0c Message: mrb: support multiple ands and or Modified files: lib/mrb/scripts/expression_size_estimator.rb test/query_optimizer/suite/test_estimate_size.rb Modified: lib/mrb/scripts/expression_size_estimator.rb (+2 -0) =================================================================== --- lib/mrb/scripts/expression_size_estimator.rb 2015-02-23 14:49:23 +0900 (f932842) +++ lib/mrb/scripts/expression_size_estimator.rb 2015-02-23 14:57:14 +0900 (0dd3136) @@ -30,6 +30,8 @@ module Groonga def group_data_list(data_list) or_data_list = [[]] data_list.each do |data| + next if data.op == Operator::NOP + and_data_list = or_data_list.last if and_data_list.empty? and_data_list << data Modified: test/query_optimizer/suite/test_estimate_size.rb (+56 -0) =================================================================== --- test/query_optimizer/suite/test_estimate_size.rb 2015-02-23 14:49:23 +0900 (e68886d) +++ test/query_optimizer/suite/test_estimate_size.rb 2015-02-23 14:57:14 +0900 (9068c29) @@ -433,4 +433,60 @@ class TestEstimateSize < QueryOptimizerTestCase "type == 1")) end end + + class TestCompositeLogicalOperations < self + def setup + Groonga::Schema.define do |schema| + schema.create_table("Logs") do |table| + table.text("message") + table.time("timestamp") + table.int32("type") + end + + schema.create_table("Terms", + :type => :patricia_trie, + :default_tokenizer => "TokenBigramSplitSymbolAlpha", + :normalizer => "NormalizerAuto") do |table| + table.index("Logs", "message") + end + + schema.create_table("Times", + :type => :patricia_trie, + :key_type => :time) do |table| + table.index("Logs", "timestamp") + end + + schema.create_table("Types", + :type => :patricia_trie, + :key_type => :int32) do |table| + table.index("Logs", "type") + end + end + super + end + + def test_and_or + @logs.add(:message => "Groonga is fast", :type => 1) + @logs.add(:message => "Rroonga is fast", :type => 1) + @logs.add(:message => "Mroonga is fast", :type => 1) + @logs.add(:timestamp => "2015-02-19 02:17:00", :type => 2) + @logs.add(:timestamp => "2015-02-19 02:17:00", :type => 2) + @logs.add(:timestamp => "2015-02-19 02:18:00", :type => 2) + @logs.add(:timestamp => "2015-02-19 02:18:00", :type => 2) + @logs.add(:timestamp => "2015-02-19 02:19:00", :type => 3) + @logs.add(:timestamp => "2015-02-19 02:19:00", :type => 3) + @logs.add(:timestamp => "2015-02-19 02:19:00", :type => 3) + @logs.add(:timestamp => "2015-02-19 02:19:00", :type => 3) + + assert_equal(6, estimate_size("(" + + "message @ 'Groonga' && " + + "timestamp < '2015-02-19 02:19:00'" + + ") || " + + "(" + + "message @ 'Groonga' && " + + "timestamp < '2015-02-19 02:19:00' && " + + "type == 1" + + ")")) + end + end end -------------- next part -------------- HTML����������������������������...Download