2013-12-14 2 views
5

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 

다음 쿼리는 Neo4jClient에서 다음 오류를 제공합니다. 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))"); 

및 Xclave 또 다른 유사 업무를 수행 한 후

:

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

같은 결과 값 : 기능 평가 시간 초과.

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

C#의 쿼리에서 반환 된 모든 노드를 PointEntity 유형 목록으로 가져 오는 방법은 무엇입니까?

편집 :

이 코드에서 노드와 관계의 URI를 다시 얻을 수 있었다 : I 시도 http://craigbrettdevden.blogspot.co.uk/2013/03/retrieving-paths-in-neo4jclient.html

:

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; 

것은 여기 크레이그 브렛의 블로그에 따라 POCO를 가져 오는데 오류가 발생했습니다 :

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

오류 :

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

답변

8
내가 첫 번째 쿼리가 작동하지 않는 이유 Neo4j의 나의 버전은 내 MATCH 절에 매개 변수를 사용 두지 않을 한, 나는 지금 그것을 테스트 할 수 없습니다 말할 수 없다

. 그러나 - 나는 내 버전을 (아래) 괜찮아요. 타임 아웃 측면에서 보면 [*..150]은 잠재적 인 순회 가능성이 매우 높습니다.

당신은 실행을 시도 할 수 :

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

여기에서의 혜택을 누릴 WHERE 조항이 paramaterized한다는 것이다 :

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; 

PathsResult는 다음과 같이 정의된다.