JnBrymn / minglbot

0 stars 0 forks source link

get_user needs Not clause #26

Open JnBrymn opened 9 years ago

JnBrymn commented 9 years ago

(Ref https://github.com/JnBrymn/minglbot/issues/25)

Add the Not clause.

Use this query as a clue about how to do this:

MATCH  x
WITH 1 as c,x
MATCH x-->y
WITH c,x.id as x_id,collect(y.id) as y_ids
WHERE NOT any(y_id IN y_ids WHERE y_id IN ['c1','c2'])
  AND NOT any(y_id IN y_ids WHERE y_id IN ['c0','c2'])
RETURN c,x_id,y_ids

Basically you first get the results for all "positive" relationships (that is FriendsOf(...) rather than Not(FriendsOf(...))); this is important because these queries control the counts associated with the relationships. Then you need a list of target followers and target friends that you filter with the "negative" relationships.

One difficult consideration is where to get the list of friends and followers for the target. In the example above I directly query for all followers, but in a real query there will be a query prior to the negative part that collects a more concise list of friends and followers. It would be nice to use that if possible.

JnBrymn commented 9 years ago

This might be another possible way to implement this query - but it seems expensive:

MATCH x
WHERE  NOT x-->({id:'a1'})AND NOT x-->({id:'a2'})
RETURN x