Neo4j 如何在Cypher中聚合集合中的结果?

Neo4j 如何在Cypher中聚合集合中的结果?,neo4j,cypher,Neo4j,Cypher,我正在处理一个cypher查询(neo4jv2.1.3),其中我需要聚合来自多个集合的结果,以便在单独的分析中使用。我从下面的查询开始,返回我们感兴趣的节点和特定主机之间的所有Person节点 MATCH (person:person), (host:person {name:'Host'}), p = shortestPath((person)-[*]-(host)) WHERE person.name IN ['Steve','Jane'] RETURN collect(extract(n

我正在处理一个cypher查询(neo4jv2.1.3),其中我需要聚合来自多个集合的结果,以便在单独的分析中使用。我从下面的查询开始,返回我们感兴趣的节点和特定主机之间的所有Person节点

MATCH (person:person), (host:person {name:'Host'}),
p = shortestPath((person)-[*]-(host))
WHERE person.name IN ['Steve','Jane']
RETURN collect(extract(n IN nodes(p)| n.name))
这将返回一个集合,其中包含my WHERE条件中两个person.name值的结果

Bob, Jordan, John, Jane, Lisa, Robert, John, Bob, John, Lisa, Bob, Lisa
我想要的是聚合这些值,并列出每个值按递减计数排序的计数

Bob, 3
John, 3
Lisa, 3
Robert, 1
Jordan, 1
Jane, 1
如何在一个cypher语句中添加到查询中来实现这一点

更新: 根据@luane的回答,我必须进行调整,使其正常工作

MATCH (person:person), (host:person {name:'Host'}),
p = shortestPath((person)-[*]-(host))
WHERE person.name IN ['Steve','Jane']
WITH collect(extract(n IN nodes(p)| n.name)) as nameList 
UNWIND nameList AS name
UNWIND name as ind_name
WITH ind_name, count(*) AS count
RETURN ind_name,count
ORDER BY count DESC
您可以使用集合来计算名称:

MATCH (person:person), (host:person {name:'Host'}),
p = shortestPath((person)-[*]-(host))
WHERE person.name IN ['Steve','Jane']
with collect(extract(n IN nodes(p)| n.name)) as nameList 
unwind nameList AS name
WITH name, count(*) AS count
RETURN name,count
ORDER BY count DESC

这将返回计数为1的每个名称列表。所以…鲍勃,乔丹,约翰,简,丽莎,罗伯特1约翰,鲍勃,约翰,丽莎,鲍勃,丽莎1在你的例子中,我需要进一步放松。我将在我的问题中添加该更新。作为一个附加问题,我如何限制返回行仅显示计数大于1的行?只需在返回之前添加一个where count>1:使用name,count(*)作为count where count>1返回名称,按计数顺序按计数说明计数