Yoji Shidara
null+****@clear*****
Mon Jan 20 18:05:22 JST 2014
Yoji Shidara 2014-01-20 18:05:22 +0900 (Mon, 20 Jan 2014) New Revision: 22d85db87f1a65ff9f615b0a8b9505b6fe82ce3b https://github.com/droonga/fluent-plugin-droonga/commit/22d85db87f1a65ff9f615b0a8b9505b6fe82ce3b Merged 1ab6677: Merge branch 'output-attributes' Message: Support complex format Modified files: lib/droonga/searcher.rb test/unit/plugin/handler/test_search.rb Modified: lib/droonga/searcher.rb (+18 -12) =================================================================== --- lib/droonga/searcher.rb 2014-01-20 13:22:47 +0900 (6e833fa) +++ lib/droonga/searcher.rb 2014-01-20 18:05:22 +0900 (068e8f7) @@ -420,21 +420,11 @@ module Droonga end def format_attributes - # XXX IMPLEMENT ME!!! - attributes = nil if****@reque*****_output? - # should convert columns to an object like: - # {"_id" => {"type" => "UInt32", "vector" => false}} - attributes = {} + format_attributes_complex(output_target_attributes) else - # should convert columns to an object like: - # [{"name" => "_id", "type" => "UInt32", "vector" => false}] - attributes = output_target_attributes.collect do |attribute| - format_attribute(attribute) - end + format_attributes_simple(output_target_attributes) end - - attributes end def output_target_attributes @@ -442,6 +432,22 @@ module Droonga normalize_target_attributes(attributes) end + def format_attributes_simple(attributes) + attributes.collect do |attribute| + format_attribute(attribute) + end + end + + def format_attributes_complex(attributes) + formatted_attributes = {} + attributes.collect do |attribute| + formatted_attribute = format_attribute(attribute) + attribute_name = formatted_attribute.delete("name") + formatted_attributes[attribute_name] = formatted_attribute + end + formatted_attributes + end + def format_attribute(attribute) label = attribute[:label] source = attribute[:source] Modified: test/unit/plugin/handler/test_search.rb (+37 -0) =================================================================== --- test/unit/plugin/handler/test_search.rb 2014-01-20 13:22:47 +0900 (f065129) +++ test/unit/plugin/handler/test_search.rb 2014-01-20 18:05:22 +0900 (280833c) @@ -260,6 +260,43 @@ class SearchHandlerTest < Test::Unit::TestCase }) end + def test_attributes_complex + assert_search({ + "sections-result" => { + "attributes" => { + "key" => { + "type" => "ShortText", + "vector" => false + }, + "title" => { + "type" => "ShortText", + "vector" => false + } + } + }, + }, + { + "queries" => { + "sections-result" => { + "source" => "Sections", + "output" => { + "format" => "complex", + "elements" => [ + "attributes" + ], + "attributes" => [ + { + "label" => "key", + "source" => "_key", + }, + "title", + ], + }, + }, + }, + }) + end + # TODO test_attributes_complex class AttributesTest < self -------------- next part -------------- HTML����������������������������...Download