How to get neighbors that I may know and exclude all neighbors that I already know

23 views
Skip to first unread message

Hazem Qannash

unread,
Nov 13, 2016, 2:57:43 AM11/13/16
to ArangoDB
Hi,

I have 2 types of edges:
  1. mayknow
  2. friend
For certain vertex How can I get all neighbors (1st, 2nd and 3rd level) and exclude all vertices that have direct "friend edge" in 1st level.

So I need to get all people that I may know but still not friends.

Jan

unread,
Nov 14, 2016, 5:46:57 AM11/14/16
to ArangoDB
Hi,

if the edges are stored in two different collections ("mayknow" and "friends") then one solution would be to run the normal traversal for "mayknow" and exclude friends for each visited vertex:

LET startNode = 'people/a'
FOR v IN 1..3 OUTBOUND startNode mayknow
  FILTER LENGTH(FOR tmp IN friend FILTER tmp._from == startNode && tmp._to == v._id RETURN 1) == 0
  RETURN v

Note that the above uses direction "OUTBOUND", which is probably not right. If the edges in your graph are always pointing into another direction, you should use the appropriate directions instead.
Best regards
Jan
Reply all
Reply to author
Forward
0 new messages