Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Neo4j:如何返回深层节点数据_Neo4j_Cypher - Fatal编程技术网

Neo4j:如何返回深层节点数据

Neo4j:如何返回深层节点数据,neo4j,cypher,Neo4j,Cypher,数据集 CREATE (u1:User {number: 1}), (u2:User {number: 2}), (r1:Room {name: 'r1'}), (r2:Room {name: 'r2'}), (d1:UnavailableDate {date: '1/1/2016'}), (d2:UnavailableDate {date: '1/2/2016'}), (i1:Image {url: 'http://..'}), (i2:Image {url: 'http://

数据集

CREATE
  (u1:User {number: 1}), (u2:User {number: 2}),
  (r1:Room {name: 'r1'}), (r2:Room {name: 'r2'}),
  (d1:UnavailableDate {date: '1/1/2016'}), (d2:UnavailableDate {date: '1/2/2016'}),
  (i1:Image {url: 'http://..'}), (i2:Image {url: 'http://..'}),(i3:Image {url: 'http://..'}),
  (pA:Place {name: 'P'}),
  (u1)<-[:house_mate]-(pA)-[:owner_of]->(u2),
  (pA)<-[:place]-(r1),
  (pA)<-[:place]-(r2),
  (r1)<-[:room]-(d1),
  (r1)<-[:room]-(d2),
  (r2)<-[:room]-(i1),
  (r2)<-[:room]-(i2),
  (r1)<-[:room]-(i3)
结果 在这里,我想弄清楚

地点在结果上应该是不同的 每个房间都应该在房间结果中将其不可用的日期和图像作为单独的数组 owner&housemate阵列看起来不错,应该是这样 问题是图像和日期的收集应在房间内,而不是在现场


有什么帮助吗?

这可能接近您想要的:

MATCH (place:`Place` {name: 'P'})-[:place]-(room:Room)
OPTIONAL MATCH (place)-[tenant:owner_of|house_mate]-(u:User)
WITH place, room, TYPE(tenant) AS type, u
OPTIONAL MATCH (room)-[:room]-(date:UnavailableDate)
OPTIONAL MATCH (room)-[:room]-(image:Image)
WITH place, room,
     collect(image) AS images,
     collect(date) AS dates,
     collect(DISTINCT {type: type, u: u}) AS tenants
RETURN place,
       collect({room: room, images: images, dates: dates}) AS room_data,
       [tenant IN tenants WHERE tenant.type = 'owner_of'   | [tenant.u]][0] AS owner_array,
       [tenant IN tenants WHERE tenant.type = 'house_mate' | [tenant.u]] AS house_mates_array;
结果如下:

╒════════════╤══════════════════════════════════════════════════════════════════════╤══════════════╤═══════════════════╕
│"place"     │"room_data"                                                           │"owner_array" │"house_mates_array"│
╞════════════╪══════════════════════════════════════════════════════════════════════╪══════════════╪═══════════════════╡
│{"name":"P"}│[{"room":{"name":"r2"},"images":[{"url":"http://.."},{"url":"http://..│[{"number":2}]│[[{"number":1}]]   │
│            │"},{"url":"http://.."},{"url":"http://.."}],"dates":[]},{"room":{"name│              │                   │
│            │":"r1"},"images":[{"url":"http://.."},{"url":"http://.."},{"url":"http│              │                   │
│            │://.."},{"url":"http://.."}],"dates":[{"date":"1/1/2016"},{"date":"1/2│              │                   │
│            │/2016"},{"date":"1/1/2016"},{"date":"1/2/2016"}]}]                    │              │                   │
└────────────┴──────────────────────────────────────────────────────────────────────┴──────────────┴───────────────────┘

这可能接近您想要的:

MATCH (place:`Place` {name: 'P'})-[:place]-(room:Room)
OPTIONAL MATCH (place)-[tenant:owner_of|house_mate]-(u:User)
WITH place, room, TYPE(tenant) AS type, u
OPTIONAL MATCH (room)-[:room]-(date:UnavailableDate)
OPTIONAL MATCH (room)-[:room]-(image:Image)
WITH place, room,
     collect(image) AS images,
     collect(date) AS dates,
     collect(DISTINCT {type: type, u: u}) AS tenants
RETURN place,
       collect({room: room, images: images, dates: dates}) AS room_data,
       [tenant IN tenants WHERE tenant.type = 'owner_of'   | [tenant.u]][0] AS owner_array,
       [tenant IN tenants WHERE tenant.type = 'house_mate' | [tenant.u]] AS house_mates_array;
结果如下:

╒════════════╤══════════════════════════════════════════════════════════════════════╤══════════════╤═══════════════════╕
│"place"     │"room_data"                                                           │"owner_array" │"house_mates_array"│
╞════════════╪══════════════════════════════════════════════════════════════════════╪══════════════╪═══════════════════╡
│{"name":"P"}│[{"room":{"name":"r2"},"images":[{"url":"http://.."},{"url":"http://..│[{"number":2}]│[[{"number":1}]]   │
│            │"},{"url":"http://.."},{"url":"http://.."}],"dates":[]},{"room":{"name│              │                   │
│            │":"r1"},"images":[{"url":"http://.."},{"url":"http://.."},{"url":"http│              │                   │
│            │://.."},{"url":"http://.."}],"dates":[{"date":"1/1/2016"},{"date":"1/2│              │                   │
│            │/2016"},{"date":"1/1/2016"},{"date":"1/2/2016"}]}]                    │              │                   │
└────────────┴──────────────────────────────────────────────────────────────────────┴──────────────┴───────────────────┘

重复项来自背对背的可选匹配项。您将获得u、日期和图像的所有组合的交叉积。为了避免这种情况,您需要在每次收集后立即收集。 或者,更好的方法是,使用立即将结果放入集合,并在最终集合中使用,将日期和图像添加到每个关联的房间中:

MATCH (place:`Place` {name: 'P'})
WITH place, [(place)-[:owner_of]-(u:User) | u] as owner_array, [(place)-[:house_mate]-(u:User) | u] as house_mates_array
MATCH (p)-[:place]-(room:Room)
WITH place, owner_array, house_mates_array, room, [(room)-[:room]-(date:UnavailableDate) | date] as dates, [(room)-[:room]-(image:Image) | image] as images
RETURN place, collect(room {.*, dates, images}) as rooms, owner_array, house_mates_array

重复项来自背对背的可选匹配项。您将获得u、日期和图像的所有组合的交叉积。为了避免这种情况,您需要在每次收集后立即收集。 或者,更好的方法是,使用立即将结果放入集合,并在最终集合中使用,将日期和图像添加到每个关联的房间中:

MATCH (place:`Place` {name: 'P'})
WITH place, [(place)-[:owner_of]-(u:User) | u] as owner_array, [(place)-[:house_mate]-(u:User) | u] as house_mates_array
MATCH (p)-[:place]-(room:Room)
WITH place, owner_array, house_mates_array, room, [(room)-[:room]-(date:UnavailableDate) | date] as dates, [(room)-[:room]-(image:Image) | image] as images
RETURN place, collect(room {.*, dates, images}) as rooms, owner_array, house_mates_array

感谢低效查询,我从@IverseFalconTanks中学到了很多低效查询,我从@IverseFalconTanks@cybersam中学到了很多您的查询也给出了正确的结果:谢谢@cybersam您的查询也给出了正确的结果: