Kouhei Sutou
null+****@clear*****
Thu Dec 8 21:40:00 JST 2016
Kouhei Sutou 2016-12-08 21:40:00 +0900 (Thu, 08 Dec 2016) New Revision: 709a97d677bdc6642cb915ad186bb8b167c21587 https://github.com/groonga/groonga-command/commit/709a97d677bdc6642cb915ad186bb8b167c21587 Message: Change Select#slices return type It shouldn't return Select because Select has too much meaningless methods for slice. We should define Slice for slice like Drillown for drilldown. Modified files: lib/groonga/command/select.rb test/command/test-select.rb Modified: lib/groonga/command/select.rb (+31 -2) =================================================================== --- lib/groonga/command/select.rb 2016-12-08 21:37:39 +0900 (1fe4f3d) +++ lib/groonga/command/select.rb 2016-12-08 21:40:00 +0900 (fd92013) @@ -107,7 +107,7 @@ module Groonga @labeled_drilldowns ||= parse_labeled_drilldowns end - # @return [::Hash<String, Select>] The slices. + # @return [::Hash<String, Slice>] The slices. # # @since 1.3.0 def slices @@ -182,7 +182,24 @@ module Groonga def build_slices(raw_slices) slices = {} raw_slices.each do |label, raw_slice| - slices[label] = Select.new(raw_slice) + match_columns = raw_slice["match_columns"] + query = raw_slice["query"] + query_expander = raw_slice["query_expander"] + query_flags = parse_flags_value(raw_slice["query_flags"]) + filter = raw_slice["filter"] + sort_keys = parse_array_value(raw_slice["sort_keys"]) + output_columns = parse_array_value(raw_slice["output_columns"]) + offset = parse_integer_value(raw_slice["offset"]) + limit = parse_integer_value(raw_slice["limit"]) + slices[label] = Slice.new(match_columns, + query, + query_expander, + query_flags, + filter, + sort_keys, + output_columns, + offset, + limit) end slices end @@ -195,6 +212,18 @@ module Groonga :calc_types, :calc_target) end + + # @since 1.3.1 + class Slice < Struct.new(:match_columns, + :query, + :query_expander, + :query_flags, + :filter, + :sort_keys, + :output_columns, + :offset, + :limit) + end end end end Modified: test/command/test-select.rb (+41 -4) =================================================================== --- test/command/test-select.rb 2016-12-08 21:37:39 +0900 (1727e42) +++ test/command/test-select.rb 2016-12-08 21:40:00 +0900 (e2dc278) @@ -219,6 +219,35 @@ class SelectCommandTest < Test::Unit::TestCase end class SlicesTest < self + def test_full + parameters = { + "slices[book_alice].match_columns" => "tag", + "slices[book_alice].query" => "Book", + "slices[book_alice].query_expander" => "Synonyms.tag", + "slices[book_alice].query_flags" => "ALLOW_COLUMN|ALLOW_LEADING_NOT", + "slices[book_alice].filter" => "user == \"alice\"", + "slices[book_alice].sort_keys" => "_score, user", + "slices[book_alice].offset" => "10", + "slices[book_alice].limit" => "25", + } + command = select_command(parameters) + + slices = { + "book_alice" => slice(:match_columns => "tag", + :query => "Book", + :query_expander => "Synonyms.tag", + :query_flags => [ + "ALLOW_COLUMN", + "ALLOW_LEADING_NOT", + ], + :filter => "user == \"alice\"", + :sort_keys => ["_score", "user"], + :offset => 10, + :limit => 25), + } + assert_equal(slices, command.slices) + end + def test_multiple parameters = { "slices[groonga].query" => "tag:Groonga", @@ -229,12 +258,20 @@ class SelectCommandTest < Test::Unit::TestCase command = select_command(parameters) slices = { - "groonga" => select_command(:query => "tag:Groonga"), - "rroonga" => select_command(:filter => "tag == Rroonga", - :sort_keys => "date", - :output_columns => "_key, date"), + "groonga" => slice(:query => "tag:Groonga"), + "rroonga" => slice(:filter => "tag == Rroonga", + :sort_keys => ["date"], + :output_columns => ["_key", "date"]), } assert_equal(slices, command.slices) end + + def slice(parameters) + slice = Groonga::Command::Select::Slice.new + parameters.each do |key, value| + slice[key] = value + end + slice + end end end -------------- next part -------------- HTML����������������������������... 下載