[英]Neo4j Reordering a path
Is there anyway in Neo4j (maybe using PathExpander
or RelationshipExpander
) to reorder the path a traversal takes by the property of a relationship (in my case a timestamp) in java? 无论如何,Neo4j中是否存在(可能使用
PathExpander
或RelationshipExpander
)通过Java中某个关系的属性(在我的情况下为时间戳)对遍历所采用的路径进行重新排序?
I have searched almost all the api's and community discussions, but cannot find a hint. 我搜索了几乎所有的api和社区讨论,但是找不到提示。
You might create a path extender that extends a path according to the value of the property, something like this, (suppose you want an increasing order). 您可以创建一个路径扩展器,该扩展器根据属性的值来扩展路径,类似这样(假设您要增加顺序)。
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;
}
} }
Then use your path extender in your traveral, 然后在海绵体内使用路径扩展器,
TraversalDescription td = Traversal.description()
.breadthFirst()
.expand(new OrderPathExpander(YourRelationshipType, Direction.INCOMING))
.evaluator(new Evaluator() {...});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.