neo4j查询:使用collect来获取嵌套结果

时间:2015-01-20 00:49:32

标签: neo4j

我的数据集非常复杂,但为了简化我想要的内容,我可以说我有一组标有日期和时间的讨论,每个讨论都分配了一个主题。我试图找到模式:如果出现主题1,通常会出现什么?我正在观察日常趋势。我目前有以下查询:

MATCH (start:Label1)
WHERE start.topic = Topic1
WITH start
MATCH (start)-[r:FOLLOWED_BY]->(end:Label2)
WITH count(end) as ecount, r as rel, collect(end.topic) as topic
RETURN DISTINCT(r.day) AS day, topic, sum(ecount) ORDER BY day DESC;

返回:

250    Topic1  2
250    Topic2  1
250    Topic3  3  

虽然我想要以下内容:

250 Topic1[2] Topic2[1] Topic3[3]

我如何实现这一目标?我试图使用收集,我得到一个错误:不知道如何比较。

1 个答案:

答案 0 :(得分:0)

如果没有看到你试过的收藏品,有点难以说,但是这个怎么样?

MATCH (start:Label1 {topic: Topic1})-[r:FOLLOWED_BY]->(end:Label2)
WITH count(end) as ecount, r as tel, collect(end.topic) as topics
UNWIND topics AS topic
RETURN DISTINCT(r.day) AS day, collect(topic + "[" + sum(ecount) + "]")
ORDER BY day DESC;