我正在构建一个嵌套对象(一个1到多的嵌套树).或者,每个节点在每个深度上都有一个到多个,来自一个cypher查询,根据这个查询,我将返回一个包含嵌套对象的值,另一个值只包含最后一个嵌套对象中的ID数组。这是两个结果列,一个包含整个树,另一个只包含is。
使用: Seraph queryRaw(),Neo4j 2.1.3
MATCH (oa:ObjectA)-[:has]->(ob:ObjectB)-[:has]->(oc:ObjectC)<-[:extends]-(thing:ObjectThing)
WHERE ob.year = 2012
WITH oa, ob, oc, collect(thing.uuid) as uuids
WITH uuids, oa, ob, collect({name:oc.name, uuid:oc.uuid, reference:thing.uuid}) AS objectCs
WITH uuids, oa, collect({name:ob.name, year:ab.year, objectCs:objectCs}) AS objectBs
RETURN {name:oa.name, country:oa.country, objectCs:objectCs} AS objectAs, uuids as documents但是,它似乎将结果分解为多个重复值,而如果我移除初始集合,则树将被正确构建。例如:
columns: [ 'objectAs', 'documents']
data:
[
[
{
name:'oa name',
country: 'oa country',
objectBs:
[ // one to many
{
name: 'ob name',
year: 2013...
... array of one to many oc nested objects ...}
}
]
},
[ '0000494949499' ]
],
[
{
name:'oa other name',
country: 'oa other country',
objectBs: [{ ... one to many nested objects like above...}]
},
[ '1234124331243' ]
]
]
MATCH (oa:ObjectA)-[:has]->(ob:ObjectB)-[:has]->(oc:ObjectC)<-[:extends]-(thing:ObjectThing)
WHERE ob.year = 2012
WITH oa, ob, collect({name:oc.name, uuid:oc.uuid, reference:thing.uuid}) AS objectCs
WITH oa, collect({name:ob.name, year:ab.year, objectCs:objectCs}) AS objectBs
RETURN {name:oa.name, country:oa.country, objectCs:objectCs} AS objectAs
columns: [ 'objectAs']
data:
[
[
{
name:'oa name',
country: 'oa country',
objectBs: [{ ... nested objects ...}]
},
{
name:'oa other name',
country: 'oa other country',
objectBs: [{ ... nested objects ...}]
}
]
]我想得到以下几点:
columns: [ 'objectAs', 'documents']
data:
[
[ // index 0 would represent column 'objectAs'
{
name:'oa name',
country: 'oa country',
objectBs: [{ ... nested objects ...}]
},
{
name:'oa other name',
country: 'oa other country',
objectBs: [{ ... nested objects ...}]
}
]
[ // index 1 would represent column 'documents'
'0000494949499',
'1234124331243'
]
]简单地说,我只是想构建一个嵌套的结果,从所有的1到许多向下4个级别,但有一个单独的结果列的所有UUID发现在最后(事物)节点,也就是说,我不希望迭代密码结果收集他们所有.。
发布于 2014-12-10 07:49:22
我认为你也必须把这些uuid集合起来:
例如:
MATCH (oa:ObjectA)-[:has]->(ob:ObjectB)-[:has]->(oc:ObjectC)<-[:extends]-(thing:ObjectThing)
WHERE ob.year = 2012
WITH oa, ob, oc, collect(thing.uuid) as uuids
WITH collect(uuids) as uuids, oa, ob, collect({name:oc.name, uuid:oc.uuid, reference:thing.uuid}) AS objectCs
WITH collect(uuids) as uuids, oa, collect({name:ob.name, year:ab.year, objectCs:objectCs}) AS objectBs
RETURN {name:oa.name, country:oa.country, objectCs:objectCs} AS objectAs, uuids as documents如果您不希望拥有uuid的嵌套集合,则可以这样做。
reduce(a=[]; x in collect(uuids) | a + x)发布于 2014-12-10 12:47:27
您需要在同一个thing子句中收集WITH in和ObjectC:
MATCH (oa:ObjectA)-[:has]->(ob:ObjectB {year: 2012})-[:has]->(oc:ObjectC)<-[:extends]-(thing:ObjectThing)
WITH oa, ob, collect({name:oc.name, uuid:oc.uuid, reference:thing.uuid}) AS objectCs, collect(thing.uuid) as uuids
WITH uuids, oa, collect({name:ob.name, year:ab.year, objectCs:objectCs}) AS objectBs
RETURN {name:oa.name, country:oa.country, objectCs:objectCs} AS objectAs, uuids as documentshttps://stackoverflow.com/questions/27382580
复制相似问题