use of org.neo4j.server.plugins.Description in project neo4j-documentation by neo4j.
the class ShortestPath method shortestPath.
@Description("Find the shortest path between two nodes.")
@PluginTarget(Node.class)
public Iterable<Path> shortestPath(@Source Node source, @Description("The node to find the shortest path to.") @Parameter(name = "target") Node target, @Description("The relationship types to follow when searching for the shortest path(s). " + "Order is insignificant, if omitted all types are followed.") @Parameter(name = "types", optional = true) String[] types, @Description("The maximum path length to search for, default value (if omitted) is 4.") @Parameter(name = "depth", optional = true) Integer depth) {
PathExpander<?> expander;
List<Path> paths = new ArrayList<>();
if (types == null) {
expander = PathExpanders.allTypesAndDirections();
} else {
PathExpanderBuilder expanderBuilder = PathExpanderBuilder.empty();
for (int i = 0; i < types.length; i++) {
expanderBuilder = expanderBuilder.add(RelationshipType.withName(types[i]));
}
expander = expanderBuilder.build();
}
try (Transaction tx = source.getGraphDatabase().beginTx()) {
PathFinder<Path> shortestPath = GraphAlgoFactory.shortestPath(expander, depth == null ? 4 : depth.intValue());
for (Path path : shortestPath.findAllPaths(source, target)) {
paths.add(path);
}
tx.success();
}
return paths;
}
Aggregations