Search code examples
springneo4jspring-data-neo4j-4neo4j-ogm

Is there a way to use PathFinder from GraphAlgoFactory with spring-data


I took a look at movies-java-spring-data-neo4j-4 and I love it, but I want to use PathFinder from GraphAlgoFactory with spring-data 4.1.1.RELEASE.

I want to create some sort of Roadmap in my db and use the RestController to find a path between two given nodes. (Basically the second (A*) example from here: neo4j-docs-graph-algo)

PathFinder<WeightedPath> astar = GraphAlgoFactory.aStar(
        PathExpanders.allTypesAndDirections(),
        doubleCostEvaluator, estimateEvaluator);
path = astar.findSinglePath(start, end);

findSinglePath needs an Object of org.neo4j.graphdb.Node is there a way to get this from a NodeEntity?

The only way I could find is using the EmbeddedDriver and looking up the node myself:

EmbeddedDriver embeddedDriver = (EmbeddedDriver) Components.driver();
GraphDatabaseService databaseService = embeddedDriver.getGraphDatabaseService();
Node node = databaseService.findNode(...)

Is there an easier way, preferably via HttpDriver?


Solution

  • The HTTP Driver does not provide access to the underlying graph database. You can write a stored procedure and call it via the session/template/repository query methods.

    Here are some examples of stored procedures for graph algorithms- https://github.com/neo4j-contrib/neo4j-apoc-procedures/#graph-algorithms-work-in-progress