0
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。

4

2 回答 2

0

您可以return rels(p) as rels只返回关系。或nodes(p)ftm。

如果您只对路径节点的名称感兴趣,请使用提取。

return extract(n in nodes(p) : n.name) as names
于 2012-10-07T20:59:46.423 回答
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>
于 2012-10-05T02:49:24.420 回答