2

考虑代码

int numberOfFriends = 0;
String output = neoNode.getProperty( "name" ) + "'s friends:\n";
Traverser friendsTraverser = getFriends( neoNode );
for ( Path friendPath : friendsTraverser )
{
output += "At depth " + friendPath.length() + " => "
          + friendPath.endNode()
                  .getProperty( "name" ) + "\n";
numberOfFriends++;
}
output += "Number of friends found: " + numberOfFriends + "\n";

这将为我们提供以下输出:

Thomas Anderson's friends:
At depth 1 => Trinity
At depth 1 => Morpheus
At depth 2 => Cypher
At depth 3 => Agent Smith
Number of friends found: 4

我想将搜索限制在深度 2。我该怎么办?

4

1 回答 1

6

利用

Traversal.description().evaluator(Evaluators.toDepth(2))
于 2013-03-16T14:16:26.303 回答