[Groonga-commit] droonga/fluent-plugin-droonga at c7de115 [output-attributes] Support output attributes in the simplest case

Back to archive index

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: c7de11501d9c2d3ddd4188f04e58eb780ae714be
  https://github.com/droonga/fluent-plugin-droonga/commit/c7de11501d9c2d3ddd4188f04e58eb780ae714be

  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-15 20:07:58 +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-15 20:07:58 +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����������������������������...
Download 



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