2013-12-14 16 views
5

Ho la seguente query di Cypher che funziona correttamente con Neo4j 2.0.0.Restituisce tutti i nodi nel percorso più breve come elenco di oggetti

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

la seguente query nel Neo4jClient dà l'errore: funzione di valutazione scaduta.

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))"); 

E Dopo aver seguito un altro lavoro simile sul Xclave:

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

Il valore Risultati come: funzione di valutazione scaduta.

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)"), 
       }); 

Come posso ottenere tutti i nodi restituiti dalla query in C# come un elenco dei tipi PointEntity?

EDIT:

sono stato in grado di ottenere indietro le URI dei nodi e delle relazioni da questo codice:

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; 

seguito il blog di Craig Brett qui: http://craigbrettdevden.blogspot.co.uk/2013/03/retrieving-paths-in-neo4jclient.html

ho provato per ottenere il POCO ma ha ottenuto l'errore:

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

Errore:

'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?) 

risposta

8

non posso dire perché la prima query non funziona, non posso provarlo in questo momento come la mia versione di Neo4j non mi permette di utilizzare i parametri nel mio MATCH clausola . Tuttavia, ottengo la mia versione (qui sotto) che risponde bene. In termini di tempismo, lo [*..150] è un potenziale attraversamento abbastanza ampio.

Si potrebbe provare a correre:

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; 

Dove PathsResult è definito come:

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

Il vantaggio è che i WHERE clausole sono parametrizzato.

Problemi correlati