Reputation: 5550
I have a traditional social media graph where a user makes a post, other users comment on that post, and users can block other users. I'm trying to create a traversal that excludes comments where the commenting user has a block
edge from the posting user (the posting user has blocked the commenting user, exclude their comments).
g.addV("user").as("poster")
.addV("post")
.addV("user").as("commenter")
.addV("comment")
.addE("post").from("poster").to("post")
.addE("comment").from("commenter").to("comment")
.addE("comment").from("comment").to("post")
.addE("block").from("poster").to("commenter")
This is as far as I got but doesn't compile:
g.V()
.hasLabel("comment")
.as("comment")
.not(
__.in_("comment")
.as("commenter")
.select("comment")
.where(
__.out("comment")
.in_("post")
.out("block")
.hasId(__.select("commentOwner").id()) // the poster is blocking the commenter
)
)
This doesn't work but is the general idea. Exclude comments where the owner of the post is blocking the commenter. How can I construct this traversal?
Upvotes: 2
Views: 123
Reputation: 877
I modified your dataset to have 2 comments on the post. 1 from the blocked user and 1 from allowed user.
(Also changed labels to more clearly represent the action in edge labels)
g.addV("user").as("poster")
.addV("post").as("post")
.addV("user").as("commenter")
.addV("user").property("name","user1").as("commenter1") # USERS
.addV("comment").property("value", "commented by first user").as("comment")
.addV("comment").property("value", "commented by second user").as("comment1") # COMMENTS
.addE("posted").from("poster").to("post")
.addE("commentedBy").from("commenter").to("comment")
.addE("commentedBy").from("commenter1").to("comment1")
.addE("commentedOn").from("comment").to("post")
.addE("commentedOn").from("comment1").to("post")
.addE("block").from("poster").to("commenter")
Then this below query should do the trick:
g.V().
hasLabel("user").as("poster").
out("posted").
in("commentedOn").as("comments").
not(in("commentedBy").in("block").where(eq("poster"))).
valueMap()
( It gives all the comments on the post by the user, from the commenters who are not blocked the user.)
Upvotes: 3