Skip to content

Commit

Permalink
Support "_nsubrecs" source with "groupBy" and "sortBy"
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Mar 20, 2014
1 parent 7116db5 commit fe5aad6
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/droonga/searcher.rb
Expand Up @@ -449,7 +449,12 @@ def format_attributes(attributes, table)
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
Expand Down
33 changes: 33 additions & 0 deletions test/command/suite/search/group/subrecord/with-sort.catalog.json
@@ -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"
}
}
}
}
}
}
}
34 changes: 34 additions & 0 deletions test/command/suite/search/group/subrecord/with-sort.expected
@@ -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!"
]
]
]
]
}
}
}
]
80 changes: 80 additions & 0 deletions test/command/suite/search/group/subrecord/with-sort.test
@@ -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"
]
}
]
}
}
}
}
}

0 comments on commit fe5aad6

Please sign in to comment.