如何使用 Gremlin 从我在 Titan 中关注的所有用户(边缘)获取帖子(顶点)
Posted
技术标签:
【中文标题】如何使用 Gremlin 从我在 Titan 中关注的所有用户(边缘)获取帖子(顶点)【英文标题】:How to get Post (Vertex) from all users whom I've followed (Edge) in Titan using Gremlin 【发布时间】:2016-09-05 04:28:45 【问题描述】:我正在使用以下查询获取我关注的所有用户的列表:-
g.v(2304).out('关注')
回应:
"success": true,
"results":
[
"Type": "User",
"CreatedTime": "2016-03-16T18:39:48.5000845Z",
"Username": "funoverflow24x7@gmail.com",
"FirstName": "Joany",
"CoverImageUrl": "https://s3-ap-southeast-1.amazonaws.com/urnotice/OrbitPage/User/Sumit/WallPost/947174ae-3e60-4dd0-877f-cc988fae3888.jpg",
"ImageUrl": "https://s3-ap-southeast-1.amazonaws.com/urnotice/OrbitPage/User/Sumit/WallPost/f4f6901c-64c4-425b-929b-43936c53eaba.png",
"LastName": "Ashtana",
"Gender": "male",
"_id": 768,
"_type": "vertex"
,
"Type": "User",
"CreatedTime": "2016-04-05T16:36:49.3740440Z",
"Username": "urnoticemail@gmail.com",
"FirstName": "Maria",
"CoverImageUrl": "https://s3-ap-southeast-1.amazonaws.com/urnotice/images/companyRectangleImageNotAvailable.png",
"ImageUrl": "https://s3-ap-southeast-1.amazonaws.com/urnotice/users/female_professional.png",
"LastName": "Sharapova",
"Gender": "female",
"_id": 5120256,
"_type": "vertex"
,
"Type": "User",
"CreatedTime": "2016-04-12T07:42:18.8036554Z",
"Username": "abhinavsrivastava189+1@gmail.com",
"FirstName": "Abhi",
"CoverImageUrl": "https://s3-ap-southeast-1.amazonaws.com/urnotice/OrbitPage/User/Sumit/WallPost/afd0d047-0d1c-4391-8f88-95f7775c615f.jpg",
"ImageUrl": "https://s3-ap-southeast-1.amazonaws.com/urnotice/OrbitPage/User/Sumit/WallPost/fd0842d4-579b-4896-9525-945f8f718816.JPG",
"LastName": "Sri",
"Gender": "male",
"_id": 12800512,
"_type": "vertex"
,
"Type": "User",
"CreatedTime": "2016-04-15T07:51:34.3867249Z",
"Username": "786goopchup@gmail.com",
"FirstName": "Goop",
"CoverImageUrl": "",
"ImageUrl": "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg",
"LastName": "Chup",
"Gender": "NA",
"_id": 17928960,
"_type": "vertex"
,
"Type": "User",
"CreatedTime": "2016-04-20T03:25:30.0753729Z",
"Username": "sumit@thirdeyeinc.com",
"FirstName": "Kunal",
"CoverImageUrl": "https://s3-ap-southeast-1.amazonaws.com/urnotice/OrbitPage/User/Sumit/WallPost/ee167d15-52bb-4f4f-99fb-038f27eee1dc.jpeg",
"ImageUrl": "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg",
"LastName": "Sharma",
"Gender": "NA",
"_id": 23041024,
"_type": "vertex"
],
"version": "2.5.0",
"queryTime": 21.94298
我正在使用以下查询获取特定用户的帖子:
gv(396800).in('WallPost').sort a, b -> b.PostedTime a.PostedTime .()[0..3].transform [postInfo :它,cmetsInfo: it.in('Comment').sort a, b -> b.PostedTime a.PostedTime .()[0..5].transform[commentInfo:it , 评论者:it.in('Created')],userInfo:it.in('Created')]
我得到了回应:
"success": true,
"results": [
"postInfo":
"PostImage": "",
"Type": "Post",
"PostedByUser": "sumit@thirdeyeinc.com",
"PostedTime": "2016-04-29T11:48:17.5069984Z",
"PostedTimeLong": 635975272975069984,
"PostMessage": "testing new post. on pooja",
"_id": 30729984,
"_type": "vertex"
,
"commentsInfo": [
],
"userInfo": [
"Type": "User",
"CreatedTime": "2016-04-20T03:25:30.0753729Z",
"Username": "sumit@thirdeyeinc.com",
"FirstName": "Kunal",
"CoverImageUrl": "https://s3-ap-southeast-1.amazonaws.com/urnotice/OrbitPage/User/Sumit/WallPost/ee167d15-52bb-4f4f-99fb-038f27eee1dc.jpeg",
"ImageUrl": "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg",
"LastName": "Sharma",
"Gender": "NA",
"_id": 23041024,
"_type": "vertex"
]
],
"version": "2.5.0",
"queryTime": 383.759295
我想获取我关注的所有用户的帖子,并根据 post Vertex 的 PostTime 降序排列。 我已经尝试了很多,但我没有得到任何方法来实现这一点。
【问题讨论】:
【参考方案1】:你做得对。只需首先获取您关注的所有顶点,然后在所有顶点上应用您的 get wall post 逻辑,它就会给您想要的结果。
g.v(2304).out('Follow').in('WallPost').sort
a, b -> b.PostedTime <=> a.PostedTime
.()[0..3]
.transform
[
postInfo: it,
commentsInfo: it.in('Comment').sort
a, b -> b.PostedTime <=> a.PostedTime
.()[0..5].
transform
[
commentInfo: it,
commentedBy: it.in('Created')
]
,
userInfo:it.in('Created')
]
因此它会为您提供您关注的所有帖子的列表,并按PostedTime
的降序排列。
【讨论】:
以上是关于如何使用 Gremlin 从我在 Titan 中关注的所有用户(边缘)获取帖子(顶点)的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 Gremlin/Titan/TinkerPop3 更新特定的边缘属性?
如何使用 Gremlin 在 Titan 中获取 Edge 日期属性大于上次访问日期的通知?
Titan Gremlin 服务器给出错误“不是 WebSocket 握手请求:缺少升级”
如何在 .net mvc 中使用 c# 创建和删除边缘属性(Titan 1.0)?