I have a graph of members and the items that they've looked at.
This data is going to be used to recommend items based on items that similar members have looked at. I'd like to sort the items based on how similar the colors of the items are. The colors are stored on the items in an array (["red", "blue", "green"]). Is there any way in cypher to compare arrays to see how many elements they have in common?
Given two nodes, n and m, that look something like:
You can do something like this:
The
FILTER
function iterates through the n.color array, binding the current value tox
(arbitrarily chosen by me, could be different). The predicate (x in m.color
) is checked for eachx
value, and if it evaluates to true, that element is pushed into the new array thatFILTER
returns. You can leave it at that to see the intersection of the two arrays (red, blue, and green in this case), or wrap it in thelength
function to see the number of colors shared between the two nodes (3 in this case).Check out the full FILTER docs here: http://docs.neo4j.org/chunked/milestone/query-functions-collection.html#functions-filter