Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return All Nodes in Shortest Path as Object List

I have the following Cypher Query which works fine in the Neo4j 2.0.0.

MATCH (ab:Point { Latitude: 24.96325, Longitude: 67.11343 }),(cd:Point { Latitude: 24.95873, Longitude: 67.10335 }),
p = shortestPath((ab)-[*..150]-(cd))
RETURN p

The following Query in Neo4jClient gives the error: Function Evaluation Timed out.

var pathsQuery =
            client.Cypher
            .Match("(ab:Point { Latitude: 24.96325, Longitude: 67.11343 }),(cd:Point { Latitude: 24.95873, Longitude: 67.10335 }), p = shortestPath((ab)-[*..150]-(cd))")
            .Return<IEnumerable<PointEntity>>("extract(n in nodes(p) : id(n))");

AND After following Another Similar work on Xclave:

http://geekswithblogs.net/cskardon/archive/2013/07/23/neo4jclient-ndash-getting-path-results.aspx

The Results value as : Function Evaluation Timed out.

var pathsQuery =
            client.Cypher
            .Match("(ab:Point { Latitude: 24.96325, Longitude: 67.11343 }),(cd:Point { Latitude: 24.95873, Longitude: 67.10335 }), p = shortestPath((ab)-[*..150]-(cd))")
            .Return(p => new PathsResult<PointEntity>
                {
                    Nodes = Return.As<IEnumerable<Node<PointEntity>>>("nodes(p)"),
                });

How can I get all the nodes returned by the query in C# as a List of PointEntity Types?

EDIT :

I was able to get back the URIs of the nodes and relations from this code:

var pathsQuery =
            client.Cypher
            .Match("(ab:Point { Latitude: 24.96325, Longitude: 67.11343 }),(cd:Point { Latitude: 24.95873, Longitude: 67.10335 }), p = shortestPath((ab)-[*..150]-(cd))")
var results = pathsQuery.Return<PathsResult>("p").Results;

Following Craig Brett's blog here: http://craigbrettdevden.blogspot.co.uk/2013/03/retrieving-paths-in-neo4jclient.html

I tried to get the POCO but got error:

var paths = pathsQuery.Returns<PathsResult>("EXTRACT(n in nodes(p) : n) AS Nodes, EXTRACT(rel in rels(p) : rel) AS Relationships", CypherResultMode.Projection).Results;

Error:

'Neo4jClient.Cypher.ICypherFluentQuery' does not contain a definition for 'Returns' and no extension method 'Returns' accepting a first argument of type 'Neo4jClient.Cypher.ICypherFluentQuery' could be found (are you missing a using directive or an assembly reference?)
like image 850
Saad Farooq Avatar asked Dec 14 '13 13:12

Saad Farooq


1 Answers

I can't say why the first query isn't working, I can't test it right now as my version of Neo4j isn't letting me use parameters in my MATCH clause. However - I do get my version (below) responding fine. In terms of timing out, the [*..150] is quite a large potential traversal.

could you try running:

var pathsQuery =
    Client.Cypher
        .Match("p = shortestPath((ab:Point)-[*..150]-(cd:Point))")
        .Where((PointEntity ab) => ab.Latitude == 24.96325)
        .AndWhere((PointEntity ab) => ab.Longitude == 67.11343)
        .AndWhere((PointEntity cd) => cd.Latitude == 24.95873)
        .AndWhere((PointEntity cd) => cd.Longitude == 67.10335)

        .Return(p => new PathsResult<PointEntity>
                        {
                            Nodes = Return.As<IEnumerable<Node<PointEntity>>>("nodes(p)"),
                            Relationships = Return.As<IEnumerable<RelationshipInstance<object>>>("rels(p)")
                        });

var res = pathsQuery.Results;

Where PathsResult is defined as:

public class PathsResult<TNode> 
{
    public IEnumerable<Node<TNode>> Nodes { get; set; }
    public IEnumerable<RelationshipInstance<object>> Relationships { get; set; }
}

The benefit here is that the WHERE clauses are paramaterized.

like image 175
Charlotte Skardon Avatar answered Nov 12 '22 04:11

Charlotte Skardon