Let's look at [a] first:
WITH ["action",'requestID','notifierType','incidentCity','eventType'] as ids
MATCH (a)-[:Parameter]->(b)
WHERE a.id in ids
WITH b, size(ids) as inputCnt, count(DISTINCT a) as cnt
WHERE cnt = inputCnt
RETURN b
We're matching to nodes with the given ids, expanding outgoing :Parameter relationships to some other node (it would be much better to use labels here of course so we could take advantage of any existing indexes for lookup instead of doing an all nodes scan, but this is a very generic example so those are omitted).
These two lines are the key:
WITH b, size(ids) as inputCnt, count(DISTINCT a) as cnt
WHERE cnt = inputCnt
Per b
node, we're getting the count of distinct a
nodes that are connected to that b
node, and that count needs to be equal to the size of the input collection. If so, that means all of the values in the input are connected to that b
node (provided there aren't duplicate values in the input collection).
The [2] example for this is only using a single input value instead of multiple, and while this still works, it's not necessarily if you're always going to be using a single input value instead of some variable number of values.
As for [3] example, this is something completely different:
MATCH (n {name:'requestID'}), (m {name:'requestID'})
RETURN apoc.coll.union(n.interests, m.interests) as interests_union,
apoc.coll.intersection(n.interests, m.interests) as interests_intersection
I'm not sure where you got this example, but it's a little odd, since both nodes in the match are using the same requestID. If we had something more like:
MATCH (n {name:'requestID1'}), (m {name:'requestID2'})
RETURN apoc.coll.union(n.interests, m.interests) as interests_union,
apoc.coll.intersection(n.interests, m.interests) as interests_intersection
that would work a bit better, as we would know these are referring to two separate nodes (again we would use labels if possible to take advantage of index lookups).
apoc.coll.union()
and apoc.coll.intersection()
are APOC functions that performs UNION or INTERSECTION operation between two lists, so each of those nodes has to have an interests
property that is a list of some sort. The results would be the unioned values and the intersected values between the two interests
lists of those nodes.
For [b], this doesn't look like a correct approach, but it's not entirely clear what it is you want.
Do you want to make sure that somewhere in the graph, there is a node (with some specific label hopefully?) with the name 'requestID' between two other nodes (with :Parameter relationships between those nodes)?
If so, then a query like this may work:
MATCH (p {name:'requestID'})
WHERE size((p)-[:Parameter]-()) > 1
RETURN p
This checks that some node with the given name has > 1 :Parameter relationship. Assuming that you can't have multiple :Parameter relationships to the same node, it would mean that there are at least two nodes connected in this way. That p
node is returned.
If that doesn't meet what you want, then you will need to supply some information about your data model and be more specific as to what exactly you want the query to do.