在Neo4j(可能使用PathExpander
或RelationshipExpander
)中是否存在重新排序遍历由java中的关系属性(在我的情况下为时间戳)的路径?
我几乎搜索了所有的api和社区讨论,但找不到提示。
答案 0 :(得分:4)
您可以创建一个路径扩展器,根据属性的值扩展路径,如下所示(假设您需要增加订单)。
public class OrderPathExpander implements PathExpander<String> {
private final RelationshipType relationshipType;
private final Direction direction;
public OrderPathExpander( RelationshipType relationshipType, Direction direction )
{
this.relationshipType = relationshipType;
this.direction = direction;
}
@Override
public Iterable<Relationship> expand(Path path, BranchState<String> state)
{
List<Relationship> results = new ArrayList<Relationship>();
if ( path.length() == 0 ) {
for ( Relationship r : path.endNode().getRelationships( relationshipType, direction ) )
{
results.add( r );
}
}
else {
for ( Relationship r : path.endNode().getRelationships( relationshipType, direction ) )
{
if ( r.getProperty("timestamp") >= (path.lastRelationship().getProperty("timestamp")) )
{
results.add( r );
}
}
}
return results;
}
@Override
public PathExpander<String> reverse()
{
return null;
}
}
然后在你的路径中使用你的路径扩展器,
TraversalDescription td = Traversal.description()
.breadthFirst()
.expand(new OrderPathExpander(YourRelationshipType, Direction.INCOMING))
.evaluator(new Evaluator() {...});