I am using Traversal API, but seems Traversal.expanderForTypes() deprecated and I do not know how to find shortest path between two nodes.
My method
public Iterable<Path> shortestPath(long firstNodeId, long secondNodeId) {
Node firstNode = null;
Node secondNode = null;
try (Transaction tx = mainServiceBean.getDatabaseService().beginTx()) {
firstNode = mainServiceBean.getDatabaseService().getNodeById(firstNodeId);
secondNode = mainServiceBean.getDatabaseService().getNodeById(secondNodeId);
PathExpander expander = Traversal.expanderForTypes();//?
PathFinder<Path> shortestPath = GraphAlgoFactory.shortestPath(expander, 4, 4);
tx.success();
return shortestPath.findAllPaths(firstNode, secondNode);
}
}
My nodes are cities and relationship between like this
Node nodeACity = mainServiceBean.getDatabaseService().createNode(ProjectLabels.City);
nodeACity .setProperty(City.NAME, CityNames.ACiTY.name());
Node nodeBCity = mainServiceBean.getDatabaseService().createNode(ProjectLabels.City);
nodeBCity.setProperty(City.NAME, CityNames.BCity.name());
Relationship ab= nodeACity .createRelationshipTo(nodeBCity , NodesRelationship.DISTANCE_TO);
ab.setProperty("distance", 124.31);
Relationship ba= nodeBCity .createRelationshipTo(nodeACity , NodesRelationship.DISTANCE_TO);
ba.setProperty("distance", 124.31);
So relationship have property distance with value.
How can use traversal API from neo4j 3? Seems a lot of changed.