[Groonga-commit] droonga/droonga-engine at d318582 [master] search: support "attributes": "*" and "output": ["attributes"]

Back to archive index

Kouhei Sutou null+****@clear*****
Tue May 27 17:54:12 JST 2014


Kouhei Sutou	2014-05-27 17:54:12 +0900 (Tue, 27 May 2014)

  New Revision: d3185822a3c17864c75643b8d41dc55cdf7eab08
  https://github.com/droonga/droonga-engine/commit/d3185822a3c17864c75643b8d41dc55cdf7eab08

  Message:
    search: support "attributes": "*" and "output": ["attributes"]

  Added files:
    test/command/suite/search/output/attributes/star.catalog.json
    test/command/suite/search/output/attributes/star.expected
    test/command/suite/search/output/attributes/star.test
  Modified files:
    lib/droonga/plugins/search.rb
    lib/droonga/plugins/search/distributed_search_planner.rb
    lib/droonga/searcher.rb
    test/command/suite/groonga/select/minimum.expected
    test/command/suite/search/attributes/array.expected
    test/command/suite/search/attributes/hash.expected
    test/command/suite/search/complex.expected
    test/command/suite/search/condition/nested.expected
    test/command/suite/search/condition/query.expected
    test/command/suite/search/condition/script.expected
    test/command/suite/search/group/string.expected
    test/command/suite/search/multiple/chained.expected
    test/command/suite/search/multiple/parallel.expected
    test/command/suite/search/range/only-output.expected
    test/command/suite/search/range/only-sort.expected
    test/command/suite/search/range/sort-and-output.expected
    test/command/suite/search/range/too-large-output-offset.expected
    test/command/suite/search/range/too-large-sort-offset.expected
    test/command/suite/search/response/records/value/time.expected
    test/command/suite/search/simple.expected
    test/command/suite/search/sort/default-offset-limit.expected
    test/command/suite/search/sort/invisible-column.expected

  Modified: lib/droonga/plugins/search.rb (+30 -2)
===================================================================
--- lib/droonga/plugins/search.rb    2014-05-27 17:28:05 +0900 (668ebc9)
+++ lib/droonga/plugins/search.rb    2014-05-27 17:54:12 +0900 (262e79e)
@@ -76,6 +76,28 @@ module Droonga
             end
           end
 
+          attributes_mapper = elements["attributes"]
+          if attributes_mapper and value["attributes"]
+            attributes = value["attributes"]
+            output_attributes = []
+            attributes_mapper["names"].each do |name|
+              if name == "*"
+                attributes.each do |attribute|
+                  next if attribute["name"].start_with?("_")
+                  output_attributes << attribute
+                end
+              else
+                attributes.each do |attribute|
+                  if attribute["name"] == name
+                    output_attributes << attribute
+                    break
+                  end
+                end
+              end
+            end
+            value["attributes"] = output_attributes
+          end
+
           records_mapper = elements["records"]
           if records_mapper and value["records"]
             if records_mapper["no_output"]
@@ -99,8 +121,14 @@ module Droonga
               complex_item
             end
           else
-            items.collect do |item|
-              item[0...attributes.size]
+            # FIXME: Compare with "attributes" value from "search" not
+            # gather parameter like the following.
+            if attributes.include?("*")
+              items
+            else
+              items.collect do |item|
+                item[0...attributes.size]
+              end
             end
           end
         end

  Modified: lib/droonga/plugins/search/distributed_search_planner.rb (+14 -1)
===================================================================
--- lib/droonga/plugins/search/distributed_search_planner.rb    2014-05-27 17:28:05 +0900 (634208f)
+++ lib/droonga/plugins/search/distributed_search_planner.rb    2014-05-27 17:54:12 +0900 (e1ff66d)
@@ -94,7 +94,7 @@ module Droonga
           output_elements = output["elements"]
           return false if output_elements.nil?
 
-          need_reduce_elements = ["count", "records"]
+          need_reduce_elements = ["count", "attributes", "records"]
           output_elements.any? do |element|
             need_reduce_elements.include?(element)
           end
@@ -127,6 +127,7 @@ module Droonga
             calculate_offset_and_limit!
             build_count_mapper_and_reducer!
             build_elapsed_time_mapper_and_reducer!
+            build_attributes_mapper_and_reducer!
             build_records_mapper_and_reducer!
           end
 
@@ -269,6 +270,18 @@ module Droonga
             }
           end
 
+          def build_attributes_mapper_and_reducer!
+            return unless @output["elements"].include?("attributes")
+
+            @reducers["attributes"] = {
+              "type" => "or",
+            }
+
+            @mappers["attributes"] = {
+              "names" => output_attribute_names,
+            }
+          end
+
           def build_records_mapper_and_reducer!
             # Skip reducing phase for a result with no record output.
             return if !@output["elements"].include?("records") || @records_limit.zero?

  Modified: lib/droonga/searcher.rb (+26 -0)
===================================================================
--- lib/droonga/searcher.rb    2014-05-27 17:28:05 +0900 (70d06c3)
+++ lib/droonga/searcher.rb    2014-05-27 17:54:12 +0900 (1b613e6)
@@ -663,6 +663,7 @@ module Droonga
 
       def output_target_attributes
         attributes =****@reque*****["attributes"]
+        attributes = expand_attributes(attributes)
         normalize_target_attributes(attributes)
       end
 
@@ -675,6 +676,31 @@ module Droonga
         formatter.format(output_target_attributes, @result.records, output_limit, output_offset)
       end
 
+      def expand_attributes(attributes, domain =****@resul*****)
+        expanded_attributes = []
+        attributes.each do |attribute|
+          if attribute.is_a?(String)
+            source = attribute
+          else
+            source = attribute["source"]
+          end
+          if source == "*"
+            real_table = domain
+            loop do
+              next_domain = real_table.domain
+              break unless next_domain.is_a?(Groonga::Table)
+              real_table = next_domain
+            end
+            real_table.columns.each do |column|
+              expanded_attributes << column.local_name
+            end
+          else
+            expanded_attributes << attribute
+          end
+        end
+        expanded_attributes
+      end
+
       def normalize_target_attributes(attributes, domain =****@resul*****)
         attributes.collect do |attribute|
           if attribute.is_a?(String)

  Modified: test/command/suite/groonga/select/minimum.expected (+24 -1)
===================================================================
--- test/command/suite/groonga/select/minimum.expected    2014-05-27 17:28:05 +0900 (046af04)
+++ test/command/suite/groonga/select/minimum.expected    2014-05-27 17:54:12 +0900 (37cbae1)
@@ -14,7 +14,30 @@
           0
         ],
         [
-
+          [
+            "_id",
+            "UInt32"
+          ],
+          [
+            "_key",
+            "ShortText"
+          ],
+          [
+            "age",
+            "Int32"
+          ],
+          [
+            "birthday",
+            "Time"
+          ],
+          [
+            "email",
+            "ShortText"
+          ],
+          [
+            "name",
+            "ShortText"
+          ]
         ]
       ]
     ]

  Modified: test/command/suite/search/attributes/array.expected (+7 -0)
===================================================================
--- test/command/suite/search/attributes/array.expected    2014-05-27 17:28:05 +0900 (c29984a)
+++ test/command/suite/search/attributes/array.expected    2014-05-27 17:54:12 +0900 (9f7d0da)
@@ -5,6 +5,13 @@
   "body": {
     "result": {
       "count": 9,
+      "attributes": [
+        {
+          "name": "section-id",
+          "type": "ShortText",
+          "vector": false
+        }
+      ],
       "records": [
         {
           "section-id": "1.1"

  Modified: test/command/suite/search/attributes/hash.expected (+18 -0)
===================================================================
--- test/command/suite/search/attributes/hash.expected    2014-05-27 17:28:05 +0900 (dc9cad9)
+++ test/command/suite/search/attributes/hash.expected    2014-05-27 17:54:12 +0900 (c739787)
@@ -5,6 +5,24 @@
   "body": {
     "result": {
       "count": 9,
+      "attributes": [
+        {
+          "name": "section-id",
+          "type": "ShortText",
+          "vector": false
+        },
+        {
+          "name": "label",
+          "type": "ShortText",
+          "vector": false
+        },
+        {
+          "name": "fixed-number"
+        },
+        {
+          "name": "fixed-string"
+        }
+      ],
       "records": [
         {
           "section-id": "1.1",

  Modified: test/command/suite/search/complex.expected (+12 -0)
===================================================================
--- test/command/suite/search/complex.expected    2014-05-27 17:28:05 +0900 (2ad0e1f)
+++ test/command/suite/search/complex.expected    2014-05-27 17:54:12 +0900 (00be5ab)
@@ -5,6 +5,18 @@
   "body": {
     "result": {
       "count": 9,
+      "attributes": [
+        {
+          "name": "_key",
+          "type": "ShortText",
+          "vector": false
+        },
+        {
+          "name": "title",
+          "type": "ShortText",
+          "vector": false
+        }
+      ],
       "records": [
         {
           "_key": "1.1",

  Modified: test/command/suite/search/condition/nested.expected (+7 -0)
===================================================================
--- test/command/suite/search/condition/nested.expected    2014-05-27 17:28:05 +0900 (7678437)
+++ test/command/suite/search/condition/nested.expected    2014-05-27 17:54:12 +0900 (cf04912)
@@ -5,6 +5,13 @@
   "body": {
     "result": {
       "count": 1,
+      "attributes": [
+        {
+          "name": "title",
+          "type": "ShortText",
+          "vector": false
+        }
+      ],
       "records": [
         [
           "Groonga storage engine"

  Modified: test/command/suite/search/condition/query.expected (+7 -0)
===================================================================
--- test/command/suite/search/condition/query.expected    2014-05-27 17:28:05 +0900 (b5317ae)
+++ test/command/suite/search/condition/query.expected    2014-05-27 17:54:12 +0900 (72606d6)
@@ -5,6 +5,13 @@
   "body": {
     "result": {
       "count": 4,
+      "attributes": [
+        {
+          "name": "title",
+          "type": "ShortText",
+          "vector": false
+        }
+      ],
       "records": [
         [
           "Groonga overview"

  Modified: test/command/suite/search/condition/script.expected (+7 -0)
===================================================================
--- test/command/suite/search/condition/script.expected    2014-05-27 17:28:05 +0900 (b5317ae)
+++ test/command/suite/search/condition/script.expected    2014-05-27 17:54:12 +0900 (72606d6)
@@ -5,6 +5,13 @@
   "body": {
     "result": {
       "count": 4,
+      "attributes": [
+        {
+          "name": "title",
+          "type": "ShortText",
+          "vector": false
+        }
+      ],
       "records": [
         [
           "Groonga overview"

  Modified: test/command/suite/search/group/string.expected (+12 -0)
===================================================================
--- test/command/suite/search/group/string.expected    2014-05-27 17:28:05 +0900 (6156bb4)
+++ test/command/suite/search/group/string.expected    2014-05-27 17:54:12 +0900 (719488a)
@@ -5,6 +5,18 @@
   "body": {
     "documents": {
       "count": 2,
+      "attributes": [
+        {
+          "name": "_key",
+          "type": "ShortText",
+          "vector": false
+        },
+        {
+          "name": "_nsubrecs",
+          "type": "Int32",
+          "vector": false
+        }
+      ],
       "records": [
         [
           "Groonga",

  Modified: test/command/suite/search/multiple/chained.expected (+14 -0)
===================================================================
--- test/command/suite/search/multiple/chained.expected    2014-05-27 17:28:05 +0900 (013596e)
+++ test/command/suite/search/multiple/chained.expected    2014-05-27 17:54:12 +0900 (52b2c1f)
@@ -5,6 +5,13 @@
   "body": {
     "Groonga": {
       "count": 4,
+      "attributes": [
+        {
+          "name": "title",
+          "type": "ShortText",
+          "vector": false
+        }
+      ],
       "records": [
         [
           "Groonga overview"
@@ -22,6 +29,13 @@
     },
     "keys": {
       "count": 4,
+      "attributes": [
+        {
+          "name": "_key",
+          "type": "ShortText",
+          "vector": false
+        }
+      ],
       "records": [
         [
           "1.9"

  Modified: test/command/suite/search/multiple/parallel.expected (+14 -0)
===================================================================
--- test/command/suite/search/multiple/parallel.expected    2014-05-27 17:28:05 +0900 (15be321)
+++ test/command/suite/search/multiple/parallel.expected    2014-05-27 17:54:12 +0900 (91c7008)
@@ -5,6 +5,13 @@
   "body": {
     "keys": {
       "count": 9,
+      "attributes": [
+        {
+          "name": "_key",
+          "type": "ShortText",
+          "vector": false
+        }
+      ],
       "records": [
         [
           "1.1"
@@ -19,6 +26,13 @@
     },
     "titles": {
       "count": 9,
+      "attributes": [
+        {
+          "name": "title",
+          "type": "ShortText",
+          "vector": false
+        }
+      ],
       "records": [
         [
           "Groonga storage engine"

  Added: test/command/suite/search/output/attributes/star.catalog.json (+23 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/search/output/attributes/star.catalog.json    2014-05-27 17:54:12 +0900 (de250fb)
@@ -0,0 +1,23 @@
+{
+  "datasets": {
+    "Droonga": {
+      "fact": "Memos",
+      "schema": {
+        "Memos": {
+          "type": "Hash",
+          "keyType": "ShortText",
+          "columns": {
+            "content": {
+              "type": "Scalar",
+              "valueType": "Text"
+            },
+            "created_at": {
+              "type": "Scalar",
+              "valueType": "Time"
+            }
+          }
+        }
+      }
+    }
+  }
+}

  Added: test/command/suite/search/output/attributes/star.expected (+27 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/search/output/attributes/star.expected    2014-05-27 17:54:12 +0900 (c0ebd41)
@@ -0,0 +1,27 @@
+{
+  "inReplyTo": "request-id",
+  "statusCode": 200,
+  "type": "search.result",
+  "body": {
+    "memos": {
+      "attributes": [
+        {
+          "name": "content",
+          "type": "Text",
+          "vector": false
+        },
+        {
+          "name": "created_at",
+          "type": "Time",
+          "vector": false
+        }
+      ],
+      "records": [
+        [
+          "I started Droonga. It is very fun!",
+          "2014-05-27T08:45:25.000000Z"
+        ]
+      ]
+    }
+  }
+}

  Added: test/command/suite/search/output/attributes/star.test (+32 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/search/output/attributes/star.test    2014-05-27 17:54:12 +0900 (4d2edcd)
@@ -0,0 +1,32 @@
+# -*- js -*-
+#@require-catalog-version 2
+#@disable-logging
+{
+  "type": "add",
+  "dataset": "Droonga",
+  "body": {
+    "table": "Memos",
+    "key": "Droonga is fun",
+    "values": {
+      "content": "I started Droonga. It is very fun!",
+      "created_at": "2014-05-27T17:45:25+09:00"
+    }
+  }
+}
+#@enable-logging
+{
+  "type": "search",
+  "dataset": "Droonga",
+  "body": {
+    "queries": {
+      "memos": {
+        "source": "Memos",
+        "output": {
+          "elements": ["attributes", "records"],
+          "attributes": ["*"],
+          "limit": 10
+        }
+      }
+    }
+  }
+}

  Modified: test/command/suite/search/range/only-output.expected (+7 -0)
===================================================================
--- test/command/suite/search/range/only-output.expected    2014-05-27 17:28:05 +0900 (d4d124a)
+++ test/command/suite/search/range/only-output.expected    2014-05-27 17:54:12 +0900 (238d005)
@@ -5,6 +5,13 @@
   "body": {
     "result": {
       "count": 9,
+      "attributes": [
+        {
+          "name": "_key",
+          "type": "ShortText",
+          "vector": false
+        }
+      ],
       "records": [
         [
           "1.3"

  Modified: test/command/suite/search/range/only-sort.expected (+7 -0)
===================================================================
--- test/command/suite/search/range/only-sort.expected    2014-05-27 17:28:05 +0900 (7343d51)
+++ test/command/suite/search/range/only-sort.expected    2014-05-27 17:54:12 +0900 (037ea64)
@@ -5,6 +5,13 @@
   "body": {
     "result": {
       "count": 9,
+      "attributes": [
+        {
+          "name": "_key",
+          "type": "ShortText",
+          "vector": false
+        }
+      ],
       "records": [
         [
           "1.7"

  Modified: test/command/suite/search/range/sort-and-output.expected (+7 -0)
===================================================================
--- test/command/suite/search/range/sort-and-output.expected    2014-05-27 17:28:05 +0900 (b41fd36)
+++ test/command/suite/search/range/sort-and-output.expected    2014-05-27 17:54:12 +0900 (5004eb6)
@@ -5,6 +5,13 @@
   "body": {
     "result": {
       "count": 9,
+      "attributes": [
+        {
+          "name": "_key",
+          "type": "ShortText",
+          "vector": false
+        }
+      ],
       "records": [
         [
           "1.3"

  Modified: test/command/suite/search/range/too-large-output-offset.expected (+8 -0)
===================================================================
--- test/command/suite/search/range/too-large-output-offset.expected    2014-05-27 17:28:05 +0900 (9df1e20)
+++ test/command/suite/search/range/too-large-output-offset.expected    2014-05-27 17:54:12 +0900 (01b7083)
@@ -5,7 +5,15 @@
   "body": {
     "result": {
       "count": 9,
+      "attributes": [
+        {
+          "name": "_key",
+          "type": "ShortText",
+          "vector": false
+        }
+      ],
       "records": [
+
       ]
     }
   }

  Modified: test/command/suite/search/range/too-large-sort-offset.expected (+8 -0)
===================================================================
--- test/command/suite/search/range/too-large-sort-offset.expected    2014-05-27 17:28:05 +0900 (9df1e20)
+++ test/command/suite/search/range/too-large-sort-offset.expected    2014-05-27 17:54:12 +0900 (01b7083)
@@ -5,7 +5,15 @@
   "body": {
     "result": {
       "count": 9,
+      "attributes": [
+        {
+          "name": "_key",
+          "type": "ShortText",
+          "vector": false
+        }
+      ],
       "records": [
+
       ]
     }
   }

  Modified: test/command/suite/search/response/records/value/time.expected (+12 -0)
===================================================================
--- test/command/suite/search/response/records/value/time.expected    2014-05-27 17:28:05 +0900 (602d15d)
+++ test/command/suite/search/response/records/value/time.expected    2014-05-27 17:54:12 +0900 (9188b64)
@@ -5,6 +5,18 @@
   "body": {
     "result": {
       "count": 2,
+      "attributes": [
+        {
+          "name": "_key",
+          "type": "ShortText",
+          "vector": false
+        },
+        {
+          "name": "start",
+          "type": "Time",
+          "vector": false
+        }
+      ],
       "records": [
         [
           "Groonga Night 3",

  Modified: test/command/suite/search/simple.expected (+12 -0)
===================================================================
--- test/command/suite/search/simple.expected    2014-05-27 17:28:05 +0900 (60b1f2e)
+++ test/command/suite/search/simple.expected    2014-05-27 17:54:12 +0900 (82b59b9)
@@ -5,6 +5,18 @@
   "body": {
     "result": {
       "count": 9,
+      "attributes": [
+        {
+          "name": "_key",
+          "type": "ShortText",
+          "vector": false
+        },
+        {
+          "name": "title",
+          "type": "ShortText",
+          "vector": false
+        }
+      ],
       "records": [
         [
           "1.1",

  Modified: test/command/suite/search/sort/default-offset-limit.expected (+7 -0)
===================================================================
--- test/command/suite/search/sort/default-offset-limit.expected    2014-05-27 17:28:05 +0900 (ea74ab2)
+++ test/command/suite/search/sort/default-offset-limit.expected    2014-05-27 17:54:12 +0900 (897855c)
@@ -5,6 +5,13 @@
   "body": {
     "result": {
       "count": 9,
+      "attributes": [
+        {
+          "name": "_key",
+          "type": "ShortText",
+          "vector": false
+        }
+      ],
       "records": [
         [
           "1.9"

  Modified: test/command/suite/search/sort/invisible-column.expected (+7 -0)
===================================================================
--- test/command/suite/search/sort/invisible-column.expected    2014-05-27 17:28:05 +0900 (0cd9e11)
+++ test/command/suite/search/sort/invisible-column.expected    2014-05-27 17:54:12 +0900 (4af624e)
@@ -5,6 +5,13 @@
   "body": {
     "result": {
       "count": 9,
+      "attributes": [
+        {
+          "name": "title",
+          "type": "ShortText",
+          "vector": false
+        }
+      ],
       "records": [
         [
           "Groonga library"
-------------- next part --------------
HTML����������������������������...
Download 



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