Given two nodes, n and m, they look something like this:
CREATE ({id: 1, color: ["red", "blue", "green", "yellow"]}) CREATE ({id: 2, color: ["red", "blue", "green", "white"]})
You can do something like this:
MATCH n, m WHERE n.id = 1 AND m.id = 2 RETURN length(FILTER(x in n.color WHERE x in m.color))
The FILTER function iterates through the n.color array, binding the current value to x (may be different by my own choice). The predicate ( x in m.color ) is checked for each value of x , and if it evaluates to true, this element is inserted into a new array returned by FILTER . You can leave this on this to see the intersection of two arrays (red, blue and green in this case) or wrap it in the length function to see the number of colors shared between two nodes (3 in this case).
Check out the full FILTER document here: http://docs.neo4j.org/chunked/milestone/query-functions-collection.html#functions-filter
source share