Reputation: 158
I'm trying to create a relationship using cosine similarity based on score
MATCH (u1:User)-[x:SCORE]->(p:Place)<-[y:SCORE]-(u2:User)
WITH SUM(x.score * y.score) AS xyDotProduct,
SQRT(REDUCE(xDot = 0.0, a IN COLLECT(x.score)) | xDot + a^2)) AS xLength,
SQRT(REDUCE(yDot = 0.0, b IN COLLECT(y.score) | yDot + b^2)) AS yLength,
u1, u2
MERGE (u1)-[s:SIMILARITY]-(u2)
SET s.similarity = xyDotProduct / (xLength * yLength)
in a docker container breaks on Java Heap..
How do I limit the query for 1000 records and then rerun for the next 1000 records?
Upvotes: 0
Views: 155
Reputation: 20185
You can add a WHERE NOT clause and a limit after the first match, for eg :
MATCH (u1:User)-[x:SCORE]->(p:Place)<-[y:SCORE]-(u2:User)
WHERE NOT (u1)-[:SIMILARITY]-(u2)
WITH u1, x, p, y, u2
LIMIT 1000
WITH SUM(x.score * y.score) AS xyDotProduct,
SQRT(REDUCE(xDot = 0.0, a IN COLLECT(x.score)) | xDot + a^2)) AS xLength,
SQRT(REDUCE(yDot = 0.0, b IN COLLECT(y.score) | yDot + b^2)) AS yLength,
u1, u2
MERGE (u1)-[s:SIMILARITY]-(u2)
SET s.similarity = xyDotProduct / (xLength * yLength)
Upvotes: 3