Neo4j 当其中一个节点已知时返回其他相关节点

Neo4j 当其中一个节点已知时返回其他相关节点,neo4j,cypher,Neo4j,Cypher,我有表格中的数据 (n:Node)-[HAS_ADDRESS]->(r:Address{name:'Goa'}), (n:Node)-[HAS_ADDRESS]->(r:Address{name:'India'}), (n:Node)-[HAS_ANCHOR]->(k:Keyword{name:'accounting'}), (n:Node)-[HAS_ANCHOR]->(k:Keyword{name:'Keyword 2'}), (n:Node)-[HAS_ANCHOR

我有表格中的数据

(n:Node)-[HAS_ADDRESS]->(r:Address{name:'Goa'}),
(n:Node)-[HAS_ADDRESS]->(r:Address{name:'India'}),
(n:Node)-[HAS_ANCHOR]->(k:Keyword{name:'accounting'}),
(n:Node)-[HAS_ANCHOR]->(k:Keyword{name:'Keyword 2'}),
(n:Node)-[HAS_ANCHOR]->(k:Keyword{name:'Keyword 3'}),
(n:Node)-[HAS_PHOTO]->(ph:Photo{name:'photo1'}),
(n:Node)-[HAS_PHOTO]->(ph:Photo{name:'photo2'}),
etc...
节点以以下格式存储

(n:Node{name:'',rating:'',international_phone_number:''})
(ph:Photo{id:''})
(k:Keyword{name:''})
我有'k'和'n'的值,所以我使用

MATCH (k:Keyword { name: 'accounting'})<-[:HAS_ANCHOR]-(p)-[:HAS_ADDRESS]->(l:Address‌​),(p)-[:HAS_PHOTO]->‌​(ph)
WHERE ph.crawl=1 AND l.name = 'Goa' 
WITH p, l
MATCH (p)-[:HAS_ADDRESS]->(other_r:Address)
return p.name as name, p.rating as rating, p.formatted_address as address,p.international_phone_number as international_phone_number,collect(ph.photo_reference) as photos, l as locations, other_r as other_addresses
ORDER BY p.rating DESC
匹配(k:关键字{name:'accounting'})(l:地址‌​),(p) -[:有照片]->‌​(博士)
其中ph.crawl=1,l.name='Goa'
用p,l
匹配(p)-[:有地址]->(其他地址)
返回p.name作为名称,p.rating作为评级,p.formatted作为地址,p.international作为国际电话号码,collect(ph.photo作为参考)作为照片,l作为位置,其他作为其他地址
按p.评级说明订购

我不知道如何获取包含所有详细信息的节点。

由于您只知道“节点1”,因此需要从第一个匹配中获取“n”,并使用它获取“r”的其他对等方

// your original query that matches n and r based on the known node r
MATCH (n:Node)->[k:HAS_ANCHOR]->(r:Node) 
WHERE r.name = 'Node 1'

// use the result of n from the first query to find peers of r 
WITH n, r
MATCH (n)-[:HAS_ANCHOR]->(other_r:Node) 
RETURN n, r, other_r
更新 根据评论,这有效吗

// match the anchor based on the keyword
MATCH (k:Keyword { name: 'accounting'})<-[:HAS_ANCHOR]-(p)
WHERE (p)-[:HAS_ADDRESS]->(:Address‌​ {name: 'Goa'})

// optionally match and collect the photos
WITH p
OPTIONAL MATCH (p)-[:HAS_PHOTO]->‌​(ph)
WHERE ph.crawl=1  

//match and collect all of the addresses 
WITH p, l, collect(ph.photo_reference) as photos
MATCH (p)-[:HAS_ADDRESS]->(r:Address)
RETURN p.name as name, 
   p.rating as rating, 
   p.formatted_address as address,
   p.international_phone_number as international_phone_number,
   photos,
   collect(r) as addresses 
ORDER BY p.rating DESC
//根据关键字匹配定位点
匹配(k:关键字{name:'accounting'})(:地址)‌​ {name:'Goa'})
//可以选择匹配和收集照片
与p
可选匹配(p)-[:HAS_PHOTO]->‌​(博士)
其中,ph.crawl=1
//匹配并收集所有地址
以p、l、collect(ph.photo_参考)作为照片
匹配(p)-[:具有\u地址]->(r:地址)
返回p.name作为name,
p、 评级为评级,
p、 格式化的_地址作为地址,
p、 国际电话号码作为国际电话号码,
照片,
收集(r)作为地址
按p.评级说明订购