我有一个带有集合的列表,但是当它返回结果时,它会在我的应用程序中输出类似的内容:
[Record<{post: node<166>, comments: [node<168>, node<168>, node<169>, node<169>], likes: [node<171>, node<172>, node<171>, node<172>], comment_count: 4, like_count: 4}>]
这是功能:
def retrieveRecords() = {
val driver = GraphDatabase.driver(neo4jUrl, AuthTokens.basic(userName, userPassword))
val session = driver.session
val script = s"MATCH (me { email: 'carl@yahoo.com' })-[rels:FRIEND*1..3]-(myfriend) WHERE ALL (r IN rels WHERE r.status = 'active') WITH COLLECT(myfriend) AS collected_friends UNWIND collected_friends AS activity MATCH (p:Posts {memberID:activity.memberID}) WITH (p) AS e OPTIONAL MATCH (g:Comments {postID:e.postID}) OPTIONAL MATCH (h:Likes {postID:e.postID}) return e AS post, COLLECT(g) AS comments, COLLECT(h) AS likes, count(g) as comment_count, count(h) as like_count"
val result: StatementResult = session.run(script)
val record_data = if (result.hasNext()) {
val e = result.next()
val data = result.list()
Some(data)
} else {
None
}
session.close()
driver.close()
record_data
}
但这是我想要的结果:
[{
"post": "{"
post_title ":"
Hadoop Tutorial ","
post_date ":"
2017 - 09 - 03 ","
post_description ":"
This tutorial is a very simple explanation on haoop ","
postID ":2,"
post_email ":"
steve @yahoo.com ","
memberID ":3}",
"comments": "[]",
"likes": "[]",
"comment_count": 0,
"like_count": 0
},
{
"post": "{"
post_title ":"
The Bamboo Tree ","
post_date ":"
2017 - 09 - 01 ","
post_description ":"
This is the wonder tree,
one of African greatest blessings ","
postID ":1,"
post_email ":"
james @yahoo.com ","
memberID ":2}",
"comments": "[{"
comment_text ":"
This is a fantastice post ","
email_email ":"
steve @yahoo.com ","
comment_email ":"
steve @yahoo.com ","
commentID ":1,"
comment_date ":"
2017 - 09 - 03 ","
postID ":1,"
memberID ":3},{"
comment_text ":"
This is a fantastice post ","
email_email ":"
steve @yahoo.com ","
comment_email ":"
steve @yahoo.com ","
commentID ":1,"
comment_date ":"
2017 - 09 - 03 ","
postID ":1,"
memberID ":3},{"
comment_text ":"
Well said ","
email_email ":"
carl @yahoo.com ","
comment_email ":"
carl @yahoo.com ","
commentID ":2,"
comment_date ":"
2017 - 09 - 03 ","
postID ":1,"
memberID ":1},{"
comment_text ":"
Well said ","
email_email ":"
carl @yahoo.com ","
comment_email ":"
carl @yahoo.com ","
commentID ":2,"
comment_date ":"
2017 - 09 - 03 ","
postID ":1,"
memberID ":1}]",
"likes": "[{"
likeID ":1,"
postID ":1,"
like_email ":"
steve @yahoo.com ","
like_date ":"
2017 - 09 - 03 ","
memberID ":3},{"
likeID ":2,"
postID ":1,"
like_email ":"
joe @yahoo.com ","
like_date ":"
2017 - 09 - 03 ","
memberID ":4},{"
likeID ":1,"
postID ":1,"
like_email ":"
steve @yahoo.com ","
like_date ":"
2017 - 09 - 03 ","
memberID ":3},{"
likeID ":2,"
postID ":1,"
like_email ":"
joe @yahoo.com ","
like_date ":"
2017 - 09 - 03 ","
memberID ":4}]",
"comment_count": 4,
"like_count": 4
}
]