如何将Neo4j的gds.shortestPath.dijkstra.stream用于elementId(node)而不是id(node)的节点?

bvhaajcl  于 12个月前  发布在  其他
关注(0)|答案(3)|浏览(122)

我有一个从节点和关系“(n1:Place)-[r:COST]->(n2:Place)"投影的图。为了找到两个名为'a'和'z'的节点之间的最便宜路径,我使用Dijkstra's shortest path algorithm

MATCH (start:Place) where 'a' = start.name
MATCH (end:Place) where 'z' = end.name
CALL gds.shortestPath.dijkstra.stream('my-graph',{
    sourceNode: id(start),
    targetNode: id(end),
    relationshipWeightProperty: 'cost'
})
YIELD nodeIds

它工作得很好,但我读到id(node):int已被弃用,在Neo4j 1.5.8中我应该使用新的elementId(node):string函数。

MATCH (start:Place) where 'a' = start.name
MATCH (end:Place) where 'z' = end.name
CALL gds.shortestPath.dijkstra.stream('my-graph',{
    sourceNode: elementId(start),
    targetNode: elementId(end),
    relationshipWeightProperty: 'cost'
})
YIELD nodeIds

但是,由于elementId()返回的是字符串而不是int,因此会导致异常:

Failed to invoke procedure `gds.shortestPath.dijkstra.stream`: Caused by: java.lang.IllegalArgumentException: Expected a node or a node id for `sourceNode`. Got String.

是否有其他选项支持使用elementId()而不是id()进行寻路?

fjnneemd

fjnneemd1#

GDS目前不支持elementId()值,因此您必须使用id()

cwxwcias

cwxwcias2#

elementID是一个字符串,但你可以像下面这样获取id:

match (n) return  toInteger(split(elementId(n),':')[2])
ejk8hzay

ejk8hzay3#

也可以将整个节点传递给过程。让GDS处理如何识别节点的其余部分。

相关问题