저는 Neo4j와 Cypher를 처음 사용합니다. 나는 우정으로 관련된 사람들의 큰 그래프를 가지고 있으며 한 사람에서 시작하여 다른 주에서 친구에게 멈추는 모든 경로를 얻고 싶습니다. 다른 주에서 온 첫 번째 친구를 보여야하지만 그 친구는 보여주지 않습니다. 기본적으로 관련 친구가 지정된 상태가 아닌 노드를 찾으면 경로가 종료되기를 원합니다. 어떤 도움이라도 대단히 감사하겠습니다.
Jack {st:'MI'}<-[Friend]-Jill {st:'MI'}<-[Friend]-John {st:'OH'}<-[Friend]-Tim {st:'OH'}
쿼리는 Jack, Jill 및 John 만 반환해야합니다. 팀이 아닙니다.
편집 / 추가
John <-[Friend]-Joan {st:'MI'}
Joan도 쿼리에 반환되지 않아야합니다.
감사!
이런 건 어때요? 같은 상태에있는 모든 친구를 매칭 한 다음 해당 경로의 끝을 선택하고 다른 상태의 끝 옆에있는 모든 친구를 매칭합니다.
MATCH path=(start:Person {name: 'Jack'})<-[:FRIEND*]-(end:Person)
WHERE end.st = start.st
AND all(p in nodes(path) where p.st = start.st)
WITH path, end
RETURN nodes(path), [(end)<-[:FRIEND]-(other:Person) WHERE other.st <> end.st | other] as other_state
이 쿼리는 other_state
노드 가있는 행만 반환합니다 .
MATCH path=(start:Person {name: 'Joe'})<-[:FRIEND*..10]-(end:Person)
WHERE end.st = start.st
AND all(p in nodes(path) where p.st = start.st)
WITH nodes(path) as same_state, [(end)<-[:FRIEND]-(other:Person) WHERE other.st <> end.st | other] as other_state
WHERE size(other_state) > 0
RETURN same_state, other_state
John, Joan 및 Tim 사용 사례를 수용하도록 변경
MATCH path=(start:Person {name: 'John'})-[:FRIEND*0..]-(end:Person)
WHERE end.st = start.st
AND all(p in nodes(path) where p.st = start.st)
WITH nodes(path) as same_state, [(end)-[:FRIEND]-(other:Person) WHERE other.st <> end.st | other] as other_state
WHERE size(other_state) > 0
RETURN same_state, other_state
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다