Neo4j - 将结果行分隔为逻辑组件

Neo4j - Separating result rows in to logical components

因为 Neo4j return 每个 return 对象都有一行,它有可能 return 行具有重复的属性。

如何将这组行转换为合适的数据结构?具体来说,我想梳理每一行并将重复值设置为 属性,对于我希望不同的值,将它们添加到数组中,这样我最终得到的内容更具可读性。比如转成这样:

[
 [“event” = “My Event”, “creator” = “Adam”, “occurrence” = “1/2/3”],
 [“event” = “My Event”, “creator” = “Adam”, “occurrence” = “2/3/4”],
 [“event” = “My Event”, “creator” = “Adam”, “occurrence” = “3/4/5”],
 [“event” = “Event 2”, “creator” = “Someone”, “occurrence” = “4/2/3”],
 [“event” = “Event 2”, “creator” = “ Someone”, “occurrence” = “4/3/4”],
 [“event” = “Event 2”, “creator” = “ Someone”, “occurrence” = “6/4/5”],
]

变成更易读、更整洁的内容,如下所示:

[
 [“event” = “My Event”, “creator” = “Adam”, “occurrence” = [“1/2/3”, “2/3/4 ”, “3/4/5”]],
 [“event” = “Event 2”, “creator” = “ Someone”, “occurrence” = [“4/2/3”, “4/3/4”, “6/4/5”]]
]

更新:

这是我的查询,

MATCH (creator:CreatingUser)-[:creator]-(event:Event), (occurrence:EventSpaceTimeOccurrence)-[:occurrence]-(event)
WHERE creator.id = '1234'
RETURN event, creator, occurrence

我期望一个事件、一个事件类型、一个创建者和许多事件。上面的查询给了我上面的结果,我想折叠成上面的非混乱版本。

根据您的修改,我会提出以下建议

MATCH (creator:CreatingUser)-[:creator]-(event:Event), (occurrence:EventSpaceTimeOccurrence)-[:occurrence]-(event)
RETURN event, creator, collect(occurrence) as eventoccurrences

这将导致事件和创建者的每个唯一组合各占一行,外加此组合的一系列事件。如果您只对特定属性感兴趣,那么您可以收集这些。例如,如果你有一个 eventdate 属性 你可以使用

RETURN event, creator, collect(occurrence.eventdate) as eventdates

现在您将获得您的 eventdate 属性 的集合。不幸的是,我不熟悉 PHP 语言驱动程序,因此无法建议功能。我知道在其他语言中有等价物可供收集。 HTH!