Let's say I have a graph with User nodes and Friendship nodes, and Users can have SENT_REQUEST and RECEIVED_REQUEST relationships to Friendship nodes. Users are connected to each other through Friendship nodes. Friendship nodes have a createdAt property, which is a dateTime() timestamp.
I want to make a query that will find out if:
- the root user has any Friendships that have a createdAt time from today, and
- any Users reachable from the root User have any Friendships that have a createdAt time from today
I tried doing this with multiple match clauses, but it doesn't work, I think because it won't re-use the outgoing SENT_REQUEST relationships from the root user to its Friendship nodes from the first MATCH clause in the second MATCH clause.
Here's my query that doesn't work (if the root user does not have a friendship created today but one of its friends does, it returns `false` for both.) If I split it into two queries, they each work on their own, so I think the logic of each MATCH clause is fine in itself, but putting them together breaks it.
How can this be improved?
MATCH (u:User {userId: "4567"})--(f:Friendship)
WHERE datetime() + duration.between(datetime(f.createdAt), datetime()) < datetime() + duration("P1D")
MATCH p=(u)-[r*]-(f2:Friendship)
WHERE datetime() + duration.between(datetime(f2.createdAt), datetime()) < datetime() + duration("P1D")
RETURN count(DISTINCT f) > 0 as userFriendshipToday, count(DISTINCT f2) > 0 as networkFriendshipToday