是否有可能从起始节点获得与其完全相距3的节点?
我知道使用Neo4J Java APi及其遍历框架可以实现这一结果:
TraversalDescription td = graphDb.traversalDescription()
.breadthFirst()
.relationships( Neo4JBenchmark.RelTypes.Knows, Direction.OUTGOING )
.uniqueness( Uniqueness.NODE_GLOBAL )
.evaluator(Evaluators.excludeStartPosition())
.evaluator(Evaluators.fromDepth(3))
.evaluator(Evaluators.toDepth(3));
ResourceIterator<Node> traverser = td.traverse(startNode).nodes().iterator();
我想知道我是否可以对Cypher做同样的事情?
答案 0 :(得分:0)
MATCH path = (a)-[:knows*3..3]->(c)
WHERE id(a) = startNodeID
WITH path,
shortestPath ( (a)-[:knows*..2]->(c) ) as sPath
WHERE sPath IS NULL
UNWIND nodes (path) as node
WITH path,
collect (distinct node) as collect
WHERE size (collect) = length (path) + 1
RETURN
DISTINCT collect [ length (path) ]
更新:添加检查没有短路径且小于所需长度。