[Groonga-commit] droonga/fluent-plugin-droonga at 69e2f04 [output-attributes] search: output attributes in subrecs at complex

Back to archive index

Yoji Shidara null+****@clear*****
Wed Jan 22 17:59:37 JST 2014


Yoji Shidara	2014-01-22 17:59:37 +0900 (Wed, 22 Jan 2014)

  New Revision: 69e2f047358d08acbebac2b38acfa4674a081baa
  https://github.com/droonga/fluent-plugin-droonga/commit/69e2f047358d08acbebac2b38acfa4674a081baa

  Message:
    search: output attributes in subrecs at complex
    
    Support attributes output for sub records in complex format

  Modified files:
    lib/droonga/searcher.rb
    test/unit/plugin/handler/test_search.rb

  Modified: lib/droonga/searcher.rb (+30 -5)
===================================================================
--- lib/droonga/searcher.rb    2014-01-22 11:15:25 +0900 (3c5f482)
+++ lib/droonga/searcher.rb    2014-01-22 17:59:37 +0900 (2e72f14)
@@ -434,27 +434,27 @@ module Droonga
 
       def format_attributes_simple(attributes)
         attributes.collect do |attribute|
-          format_attribute(attribute, @result.records)
+          format_attribute_simple(attribute, @result.records)
         end
       end
 
       def format_attributes_complex(attributes)
         formatted_attributes = {}
         attributes.collect do |attribute|
-          formatted_attribute = format_attribute(attribute, @result.records)
-          attribute_name = formatted_attribute.delete("name")
+          formatted_attribute = format_attribute_complex(attribute, @result.records)
+          attribute_name = attribute[:label]
           formatted_attributes[attribute_name] = formatted_attribute
         end
         formatted_attributes
       end
 
-      def format_attribute(attribute, table)
+      def format_attribute_simple(attribute, table)
         label = attribute[:label]
         source = attribute[:source]
         if source == "_subrecs"
           sub_record_table = table.range
           sub_attributes = attribute[:attributes].collect do |sub_attribute|
-            format_attribute(sub_attribute, sub_record_table)
+            format_attribute_simple(sub_attribute, sub_record_table)
           end
           {
             "name" => label,
@@ -472,6 +472,31 @@ module Droonga
         end
       end
 
+      def format_attribute_complex(attribute, table)
+        source = attribute[:source]
+        if source == "_subrecs"
+          sub_record_table = table.range
+          sub_attributes = {}
+          attribute[:attributes].each do |sub_attribute|
+            sub_label = sub_attribute[:label]
+            sub_attributes[sub_label] =
+              format_attribute_complex(sub_attribute, sub_record_table)
+          end
+          {
+            "attributes" => sub_attributes
+          }
+        else
+          expression = attribute[:expression]
+          if expression
+            # TODO implement
+          else
+            column = table.column(source)
+            vector = column.respond_to?(:vector?) ? column.vector? : false
+            {"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 (+0 -1)
===================================================================
--- test/unit/plugin/handler/test_search.rb    2014-01-22 11:15:25 +0900 (67e0515)
+++ test/unit/plugin/handler/test_search.rb    2014-01-22 17:59:37 +0900 (5875075)
@@ -381,7 +381,6 @@ class SearchHandlerTest < Test::Unit::TestCase
       end
 
       def test_attributes_subrecs_complex
-        pend "Not implemented"
         assert_search({
                         "sections-result" => {
                           "attributes" => {
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index