限制并跳过密码匹配查询

时间:2016-06-16 22:52:53

标签: neo4j cypher recommendation-engine

我正在尝试使用基于分数的余弦相似度创建关系

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)
Java堆中的

在docker容器中中断..

如何限制1000条记录的查询,然后重新运行接下来的1000条记录?

1 个答案:

答案 0 :(得分:3)

您可以在第一次匹配后添加WHERE NOT子句和限制,例如:

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)