2016-06-16 2 views
1

Neo4j 쿼리가 엉망입니다. Neo4j Cypher 언어로 레이블 "p"가있는 "n1"의 모든 관계가 "n6"에 대한 경로를 갖고 있는지 확인할 수 있습니까? 이미지를 참조하십시오.Neo4j의 다중 경로 관계 확인

enter image description here

답변

2

물론 그것이 가능하다는 것을 :

MATCH (n6:Node {name:"n6"}) 
MATCH (n1:Node {name:"n1"})-[r:p]->() 
WITH n1, n6, collect(r) as pRels 
RETURN ALL(x IN pRels WHERE shortestPath((n1)-[*]-(n6))) 

이 반환됩니다 참 또는 거짓

1
// End node 
MATCH (n6 {name:"n6"}) 
// Start node and neighbors 
MATCH (n1 {name:"n1"})-[:p]-(n) 
// Shortest paths through the neighbor to the end node, 
OPTIONAL MATCH p = shortestPath((n)-[*]-(n6)) 
    // which does not pass through the starting node 
    WHERE NOT n1 IN nodes(p) 
WITH 
    size(collect(distinct n)) as neighborsCount, 
    count(p) as neighborsWithPathCount 
RETURN neighborsCount = neighborsWithPathCount AND 
     neighborsWithPathCount > 0