如何使用 Gremlin 从我在 Titan 中关注(Edge)的所有用户获取 Post(Vertex)

How to get Post (Vertex) from all users whom I've followed (Edge) in Titan using Gremlin

我正在使用以下查询获取我关注的所有用户的列表:-

g.v(2304).out('Follow')

回复:

{

"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

}

我正在使用以下查询获取特定用户 post:

g.v(396800).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')] }

我正在收到回复:

{
"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,并根据 post Vertex 的 PostTime 降序排列。 我已经尝试了很多,但我没有得到任何方法如何实现这一目标。

你做得对。只需首先获取您正在关注的所有顶点,然后在所有顶点上应用您的获取墙 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')
    ]
}

因此它会为您提供所有 post 关注者的列表,并按 PostedTime.

的降序排列