如何获取路径(Neo4j)中节点属性的总值?

时间:2017-04-17 05:53:30

标签: neo4j cypher

MATCH p =(o:Order)-[r:seeks*2..8]->(o:Order)
WHERE o.Name={orderID} AND ALL(x IN tail(nodes(p)) WHERE 
SINGLE(y IN    tail(nodes(p)) WHERE x=y))
WITH p, o, r, extract(u IN nodes(p)| u.UserName) AS UserName
WHERE size(UserName) - 1 = size(apoc.coll.toSet(tail(UserName)))
RETURN extract(n IN nodes(p)| n.Name) AS OrderID, UserName, length(p) as 
Participants, endNode(r[0]) as AvailableOffers, ***reduce(s = 0, x IN 
extract(b IN nodes(p)| coalesce(b.userReputation, 0)) | s + x) AS UserRep***
ORDER BY length(p)"""

The Screenshot of my query result

我无法使用reduce函数获取节点中属性的总和...

1 个答案:

答案 0 :(得分:0)

我无法重现您的查询,但我认为我发现您的问题是同时使用reduce和extract。试试这个

MATCH p =(o:Order)-[r:seeks*2..8]->(o:Order)
WHERE o.Name={orderID} AND ALL(x IN tail(nodes(p)) WHERE 
SINGLE(y IN    tail(nodes(p)) WHERE x=y))
WITH p, o, r, extract(u IN nodes(p)| u.UserName) AS UserName
WHERE size(UserName) - 1 = size(apoc.coll.toSet(tail(UserName)))
RETURN extract(n IN nodes(p)| n.Name) AS OrderID, UserName, length(p) as 
Participants, endNode(r[0]) as AvailableOffers, ***reduce(s = 0, x IN 
nodes(p)| s + coalesce(x.userReputation, 0)) AS UserRep***
ORDER BY length(p)"""