YUKI Hiroshi
null+****@clear*****
Wed May 1 17:57:46 JST 2013
YUKI Hiroshi 2013-05-01 17:57:46 +0900 (Wed, 01 May 2013) New Revision: 80e26adddd48d9c971b7778b3ba17d369db74e83 https://github.com/groonga/fluent-plugin-droonga/commit/80e26adddd48d9c971b7778b3ba17d369db74e83 Message: Control output of elements by "output.elements" as the spec Modified files: lib/droonga/plugin/handler_search.rb test/plugin/test_handler_search.rb test/test_worker.rb Modified: lib/droonga/plugin/handler_search.rb (+22 -10) =================================================================== --- lib/droonga/plugin/handler_search.rb 2013-04-30 11:00:00 +0900 (4bd057b) +++ lib/droonga/plugin/handler_search.rb 2013-05-01 17:57:46 +0900 (b39f6d3) @@ -98,12 +98,13 @@ module Droonga end def format - params = @query["output"] formatted_result = {} - format_count(params, formatted_result) - format_records(params, formatted_result) - if params["elapsedTime"] + format_count(formatted_result) + format_records(formatted_result) + if need_element_output?("startTime") formatted_result["startTime"] = @start_time.iso8601 + end + if need_element_output?("elapsedTime") formatted_result["elapsedTime"] = Time.now.to_f - @start_time.to_f end formatted_result @@ -217,15 +218,26 @@ module Droonga @result end - def format_count(params, formatted_result) - return unless params["count"] - formatted_result["count"] = @count + def need_element_output?(element) + params = @query["output"] + + elements = params["elements"] + return false if elements.nil? + + elements.include?(element) end - def format_records(params, formatted_result) - attributes = params["attributes"] - return if attributes.nil? + def format_count(formatted_result) + return unless need_element_output?("count") + formatted_result["count"] =****@resul***** + end + + def format_records(formatted_result) + return unless need_element_output?("records") + params = @query["output"] + + attributes = params["attributes"] target_attributes = normalize_target_attributes(attributes) offset = params["offset"] || 0 limit = params["limit"] || 10 Modified: test/plugin/test_handler_search.rb (+25 -2) =================================================================== --- test/plugin/test_handler_search.rb 2013-04-30 11:00:00 +0900 (1d2cd29) +++ test/plugin/test_handler_search.rb 2013-05-01 17:57:46 +0900 (8fcc049) @@ -134,6 +134,9 @@ class SearchHandlerTest < Test::Unit::TestCase "sections-result" => { "source" => "Sections", "output" => { + "elements" => [ + "records", + ], "format" => "complex", "limit" => 1, "attributes" => ["title"], @@ -184,7 +187,9 @@ class SearchHandlerTest < Test::Unit::TestCase "sections-result" => { "source" => "Sections", "output" => { - "count" => true, + "elements" => [ + "count", + ], }, }, }, @@ -203,7 +208,10 @@ class SearchHandlerTest < Test::Unit::TestCase "sections-result" => { "source" => "Sections", "output" => { - "elapsedTime" => true, + "elements" => [ + "startTime", + "elapsedTime", + ], }, }, }, @@ -235,6 +243,9 @@ class SearchHandlerTest < Test::Unit::TestCase "sections-result" => { "source" => "Sections", "output" => { + "elements" => [ + "records", + ], "format" => "complex", "limit" => 3, "attributes" => ["_key", "title"], @@ -269,6 +280,9 @@ class SearchHandlerTest < Test::Unit::TestCase "sections-result" => { "source" => "Sections", "output" => { + "elements" => [ + "records", + ], "format" => "complex", "limit" => 3, "attributes" => [ @@ -294,6 +308,9 @@ class SearchHandlerTest < Test::Unit::TestCase "sections-result" => { "source" => "Sections", "output" => { + "elements" => [ + "records", + ], "format" => "complex", "limit" => 3, "attributes" => ["_key", "title"], @@ -311,6 +328,9 @@ class SearchHandlerTest < Test::Unit::TestCase "sections-result" => { "source" => "Sections", "output" => { + "elements" => [ + "records", + ], "format" => "simple", "limit" => 3, "attributes" => ["_key", "title"], @@ -328,6 +348,9 @@ class SearchHandlerTest < Test::Unit::TestCase "sections-result" => { "source" => "Sections", "output" => { + "elements" => [ + "records", + ], "limit" => 3, "attributes" => ["_key", "title"], }, Modified: test/test_worker.rb (+3 -1) =================================================================== --- test/test_worker.rb 2013-04-30 11:00:00 +0900 (efa1d5c) +++ test/test_worker.rb 2013-05-01 17:57:46 +0900 (7ecec4c) @@ -77,7 +77,9 @@ class WorkerTest < Test::Unit::TestCase "sections" => { "source" => "Sections", "output" => { - "count" => true, + "elements" => [ + "count", + ], }, }, }, -------------- next part -------------- HTML����������������������������... ダウンロード