返回最短路径中的所有节点作为对象列表 [英] Return All Nodes in Shortest Path as Object List
问题描述
我有以下 Cypher 查询,它在 Neo4j 2.0.0 中运行良好.
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
Neo4jClient 中的以下查询给出错误:Function Evaluation Timed.
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 在 Xclave 上进行了另一项类似的工作之后:
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)"),
});
如何获取 C# 中查询返回的所有节点作为 PointEntity 类型列表?
How can I get all the nodes returned by the query in C# as a List of PointEntity Types?
我能够从这段代码中取回节点和关系的 URI:
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;
在此处关注 Craig Brett 的博客:http://craigbrettdevden.blogspot.co.uk/2013/03/retrieving-path-in-neo4jclient.html
Following Craig Brett's blog here: http://craigbrettdevden.blogspot.co.uk/2013/03/retrieving-paths-in-neo4jclient.html
我尝试获取 POCO 但出现错误:
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;
错误:
'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?)
推荐答案
我不知道为什么第一个查询不起作用,我现在无法测试它,因为我的 Neo4j 版本不允许我使用我的 MATCH
子句中的参数.但是 - 我的版本(如下)响应良好.在超时方面,[*..150]
是一个相当大的潜在遍历.
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.
你可以试试跑步吗:
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
定义为:
public class PathsResult<TNode>
{
public IEnumerable<Node<TNode>> Nodes { get; set; }
public IEnumerable<RelationshipInstance<object>> Relationships { get; set; }
}
这里的好处是 WHERE
子句是参数化的.
The benefit here is that the WHERE
clauses are paramaterized.
这篇关于返回最短路径中的所有节点作为对象列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!