0

I'm using Neo4J 2.2.5 with Spring Data and I want to calculate the shortest path between 2 nodes using Dijkstra.

This is my code :

PathFinder<WeightedPath> finder = GraphAlgoFactory
                .dijkstra(PathExpanders.forTypeAndDirection(RelationshipTypes.SEM_SIM, Direction.BOTH),
                        Constants.ADVERTISED_COST);
        WeightedPath path = finder.findSinglePath(startVertexNode, goalVertexNode);

How can I get the startVertexNode and goalVertexNode parameters? Using the cypher approach below I get to the correct data but how can I convert the Result into a Node?

Map<String, Object> params = new HashMap<String, Object>();
        params.put( "id", 0 );
        String query = "MATCH n WHERE id(n) = {id} RETURN n";

         org.neo4j.ogm.session.result.Result result = this.neo4jOperations.query(query, params);

Thanks in advance for helping me out!

Kind regards, Johan,

Luanne
  • 19,145
  • 1
  • 39
  • 51

1 Answers1

0

Since your cypher query MATCH n WHERE id(n) = {id} RETURN n returns a single node, you can use

neo4jOperations.queryForObject(Class<T> entityType, String cypherQuery, Map<String, ?> parameters)

which will return your entity directly. SDN/OGM will not give you raw nodes or relationships back from queries.

I'm not sure what you mean by "How can I get the startVertexNode and goalVertexNode parameters"

Luanne
  • 19,145
  • 1
  • 39
  • 51
  • The argument type of the findSinglePath method is org.neo4j.graphdb.Node. The question is how I can get these objects starting from an ID using SDN? – Johan Kumps Mar 02 '16 at 07:51
  • Unless you use SDN 4.1 with the embedded driver, there is no way to get a Node from the graph. If you do use the embedded driver, then you can use the embedded API to get the start and end vertex by id. But session/query won't help, because all you get back is a domain entity, not a node. – Luanne Mar 02 '16 at 08:37