String query1 = "START
a=node:node_auto_index(name=\"A\"),
m=node:node_auto_index(name=\"M\"),
b=node:node_auto_index(name=\"G\")
MATCH p=a-[*]-b-[*]-m " +
WHERE ALL(r in RELS(p) WHERE r.value >= 200) "
+ "WITH a, m, MIN(LENGTH(p)) AS l
MATCH p=a-[*]-b-[*]-m WHERE ALL(r
in RELS(p) WHERE r.value >= 200)" +
" AND LENGTH(p)=l RETURN p order by length(p) desc "; //limit 2
ExecutionResult eResult = exEngine.execute(query1);
我使用上面的查询来获取两个节点之间的所有路径。如何迭代返回的RelationShips。
答案 0 :(得分:0)
我是使用以下方法完成的,上面发布的链接有帮助。
final Iterator rels = eResult.columnAs("p");
while (rels.hasNext()){
Path path = rels.next();
Iterable<Relationship> relationships = path.relationships();
java.util.Iterator<Relationship> relIterator = relationships.iterator();
while (relIterator.hasNext()){
Relationship rel = relIterator.next();
String aNode = (String) rel.getStartNode().getProperty("name");
String zNode = (String) rel.getEndNode().getProperty("name");
Long value = (Long) rel.getProperty("value");
System.out.println(aNode +" is connected to "+zNode + " with value "+value);
}
}
</code>
答案 1 :(得分:0)
您只需return rels(p) as rels
即可返回关系。或nodes(p)
ftm。
如果您只对路径的节点名称感兴趣,请使用extract。
return extract(n in nodes(p) : n.name) as names