Yoji Shidara
null+****@clear*****
Mon Jan 20 13:22:47 JST 2014
Yoji Shidara 2014-01-20 13:22:47 +0900 (Mon, 20 Jan 2014) New Revision: aee909c6aa9d6803090e4cda3c819f76d7f4fadb https://github.com/droonga/fluent-plugin-droonga/commit/aee909c6aa9d6803090e4cda3c819f76d7f4fadb Merged 1ab6677: Merge branch 'output-attributes' Message: Support output attributes in the simplest case Restrictions: * simple format only * no _subrecs support * no expression support Modified files: lib/droonga/searcher.rb test/unit/plugin/handler/test_search.rb Modified: lib/droonga/searcher.rb (+20 -1) =================================================================== --- lib/droonga/searcher.rb 2014-01-23 11:51:31 +0900 (b09b58c) +++ lib/droonga/searcher.rb 2014-01-20 13:22:47 +0900 (6e833fa) @@ -429,7 +429,9 @@ module Droonga else # should convert columns to an object like: # [{"name" => "_id", "type" => "UInt32", "vector" => false}] - attributes = [] + attributes = output_target_attributes.collect do |attribute| + format_attribute(attribute) + end end attributes @@ -440,6 +442,23 @@ module Droonga normalize_target_attributes(attributes) end + def format_attribute(attribute) + label = attribute[:label] + source = attribute[:source] + if source == "_subrecs" + # TODO implement + else + expression = attribute[:expression] + if expression + # TODO implement + else + column =****@resul*****(source) + vector = column.respond_to?(:vector?) ? column.vector? : false + {"name" => label, "type" => column.range.name, "vector" => vector} + end + end + end + def format_records formatted_records = nil cursor_options = { Modified: test/unit/plugin/handler/test_search.rb (+40 -0) =================================================================== --- test/unit/plugin/handler/test_search.rb 2014-01-23 11:51:31 +0900 (6a123ab) +++ test/unit/plugin/handler/test_search.rb 2014-01-20 13:22:47 +0900 (f065129) @@ -222,6 +222,46 @@ class SearchHandlerTest < Test::Unit::TestCase }) end + def test_attributes_simple + assert_search({ + "sections-result" => { + "attributes" => [ + { + "name" => "key", + "type" => "ShortText", + "vector" => false + }, + { + "name" => "title", + "type" => "ShortText", + "vector" => false + } + ] + }, + }, + { + "queries" => { + "sections-result" => { + "source" => "Sections", + "output" => { + "elements" => [ + "attributes" + ], + "attributes" => [ + { + "label" => "key", + "source" => "_key", + }, + "title", + ], + }, + }, + }, + }) + end + + # TODO test_attributes_complex + class AttributesTest < self def test_source_only expected = { -------------- next part -------------- HTML����������������������������...ダウンロード