2
Neo4j中是否有(可能使用PathExpander
或RelationshipExpander
)重新排序遍歷java中的關係屬性(在我的情況下是時間戳)的路徑?Neo4j重新排序路徑
我已經搜索了幾乎所有的api和社區討論,但無法找到提示。
Neo4j中是否有(可能使用PathExpander
或RelationshipExpander
)重新排序遍歷java中的關係屬性(在我的情況下是時間戳)的路徑?Neo4j重新排序路徑
我已經搜索了幾乎所有的api和社區討論,但無法找到提示。
您可能會創建一個路徑擴展器,根據該屬性的值來擴展路徑,如下所示(假設您希望增加順序)。
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;
}
}
然後用你的路延長你的traveral,
TraversalDescription td = Traversal.description()
.breadthFirst()
.expand(new OrderPathExpander(YourRelationshipType, Direction.INCOMING))
.evaluator(new Evaluator() {...});