Take a look at this example I generated using the Neo4j Console:
http://console.neo4j.org/?id=aq6cb3
The query should be:
MATCH (m:Movie { title: "The Matrix" })-[h1:HAS_TAG]->(t:Tag),
(t)<-[h2:HAS_TAG]-(sm:Movie),
(m)-[h:HAS_TAG]->(t0:Tag),
(sm)-[H:HAS_TAG]->(t1:Tag)
WHERE m <> sm
WITH m, sm,
collect(DISTINCT h) AS h,
collect(DISTINCT H) AS H,
sum(h1.weight*h2.weight) AS num
WITH m, sm, num,
sqrt(reduce(s = 0.0, x IN h | s +(x.weight^2))) AS den1,
sqrt(reduce(s = 0.0, x IN H | s +(x.weight^2))) AS den2
RETURN m.title, sm.title, (num/(den1*den2)) AS similarity
Which results in the following:
+---------------------------------------------------------------+
| m.title | sm.title | similarity |
+---------------------------------------------------------------+
| "The Matrix" | "The Matrix: Revolutions" | 3.859767091086958 |
| "The Matrix" | "The Matrix: Reloaded" | 1.4380667053087486 |
+---------------------------------------------------------------+
I used the reduce function to aggregate the relationship values from a distinct collection and perform the similarity index calculation.