[Groonga-commit] droonga/fluent-plugin-droonga at fe5aad6 [master] Support "_nsubrecs" source with "groupBy" and "sortBy"

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Mar 21 00:30:35 JST 2014


Kouhei Sutou	2014-03-21 00:30:35 +0900 (Fri, 21 Mar 2014)

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

  Message:
    Support "_nsubrecs" source with "groupBy" and "sortBy"

  Added files:
    test/command/suite/search/group/subrecord/with-sort.catalog.json
    test/command/suite/search/group/subrecord/with-sort.expected
    test/command/suite/search/group/subrecord/with-sort.test
  Modified files:
    lib/droonga/searcher.rb

  Modified: lib/droonga/searcher.rb (+6 -1)
===================================================================
--- lib/droonga/searcher.rb    2014-03-20 10:07:22 +0900 (970ccc0)
+++ lib/droonga/searcher.rb    2014-03-21 00:30:35 +0900 (8eb92ff)
@@ -449,7 +449,12 @@ module Droonga
     module RecordsFormattable
       def record_value(record, attribute)
         if attribute[:source] == "_subrecs"
-          record.sub_records.collect do |sub_record|
+          if record.table.is_a?(Groonga::Array)
+            target_record = record.value
+          else
+            target_record = record
+          end
+          target_record.sub_records.collect do |sub_record|
             sub_attributes = attribute[:attributes]
             format_record(sub_attributes, sub_record)
           end

  Added: test/command/suite/search/group/subrecord/with-sort.catalog.json (+33 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/search/group/subrecord/with-sort.catalog.json    2014-03-21 00:30:35 +0900 (096cc16)
@@ -0,0 +1,33 @@
+{
+  "datasets": {
+    "Droonga": {
+      "fact": "Comments",
+      "schema": {
+        "Threads": {
+          "type": "Hash",
+          "keyType": "ShortText",
+          "columns": {
+            "name": {
+              "type": "Scalar",
+              "valueType": "ShortText"
+            }
+          }
+        },
+        "Comments": {
+          "type": "Hash",
+          "keyType": "ShortText",
+          "columns": {
+            "thread": {
+              "type": "Scalar",
+              "valueType": "Threads"
+            },
+            "content": {
+              "type": "Scalar",
+              "valueType": "Text"
+            }
+          }
+        }
+      }
+    }
+  }
+}

  Added: test/command/suite/search/group/subrecord/with-sort.expected (+34 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/search/group/subrecord/with-sort.expected    2014-03-21 00:30:35 +0900 (8c2285f)
@@ -0,0 +1,34 @@
+[
+  "droonga.message",
+  0,
+  {
+    "inReplyTo": "request-id",
+    "statusCode": 200,
+    "type": "search.result",
+    "body": {
+      "comments": {
+        "count": 2,
+        "records": [
+          [
+            "groonga",
+            1,
+            [
+              [
+                "Groonga is great!"
+              ]
+            ]
+          ],
+          [
+            "ruby",
+            1,
+            [
+              [
+                "Hi! I'm a new Rubyist!"
+              ]
+            ]
+          ]
+        ]
+      }
+    }
+  }
+]

  Added: test/command/suite/search/group/subrecord/with-sort.test (+80 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/search/group/subrecord/with-sort.test    2014-03-21 00:30:35 +0900 (afe662e)
@@ -0,0 +1,80 @@
+# -*- js -*-
+#@disable-logging
+{
+  "type": "add",
+  "dataset": "Droonga",
+  "body": {
+    "table": "Threads",
+    "key": "ruby",
+    "values": {
+      "name": "Ruby"
+    }
+  }
+}
+{
+  "type": "add",
+  "dataset": "Droonga",
+  "body": {
+    "table": "Threads",
+    "key": "groonga",
+    "values": {
+      "name": "Groonga"
+    }
+  }
+}
+{
+  "type": "add",
+  "dataset": "Droonga",
+  "body": {
+    "table": "Comments",
+    "key": "1",
+    "values": {
+      "thread": "ruby",
+      "content": "Hi! I'm a new Rubyist!"
+    }
+  }
+}
+{
+  "type": "add",
+  "dataset": "Droonga",
+  "body": {
+    "table": "Comments",
+    "key": "2",
+    "values": {
+      "thread": "groonga",
+      "content": "Groonga is great!"
+    }
+  }
+}
+#@enable-logging
+{
+  "type": "search",
+  "dataset": "Droonga",
+  "body": {
+    "queries": {
+      "comments": {
+        "source": "Comments",
+        "groupBy": {
+          "key": "thread",
+          "maxNSubRecords": 10
+        },
+        "sortBy": ["_key"],
+        "output": {
+          "elements": ["count", "records"],
+          "limit": -1,
+          "attributes": [
+            "_key",
+            "_nsubrecs",
+            {
+              "label": "items",
+              "source": "_subrecs",
+              "attributes": [
+                "content"
+              ]
+            }
+          ]
+        }
+      }
+    }
+  }
+}
-------------- next part --------------
HTML����������������������������...
Download 



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