在OrientDB的shortestPath()中获取访问边

时间:2013-04-25 19:07:59

标签: java graph-databases orientdb

我是OrientDB的新手,我想使用新的shortestPath()方法来获取两个顶点之间的边。

我的工作是:

OSQLSynchQuery<T> sql = new OSQLSynchQuery<T>("select shortestpath(" + firstVertex + ", " + secondVertex + ").asString()");

List<ODocument> execute = db.query(sql);

我只能获得[#-2:1{shortestpath:[#8:1, #8:3]} v0]

所以,我想知道如何从这个输出中提取边缘(好吧,在这种情况下只有一条边,因为这两个顶点是直接连接的),或者从没有asString()的输出中提取:

[#-2:1{shortestpath:[2]} v0]

提前致谢!

3 个答案:

答案 0 :(得分:1)

OrientDB有集合和地图类型。要使集合成为结果集(您感兴趣的内容),您必须将其展平:

select flatten( shortestpath(" + firstVertex + ", " + secondVertex + ") )

要获得边缘传出边缘,有很多方法。下面几个:

select vertices.out from (
   select flatten( shortestpath(" + firstVertex + ", " + secondVertex + ") ) as vertices
)

或者:

select flatten( shortestpath(" + firstVertex + ", " + secondVertex + ").out )

答案 1 :(得分:1)

对我而言,dante或Lvca如何解释它并不起作用:

select flatten(shortestPath) from (select shortestPath(#12:0,#12:2,'BOTH')

这会导致控制台中的错误或OrientDB Studio中没有返回的记录。

相反,当我使用函数结果的别名时,它最终起作用了。所以也许试试这个表格:

select flatten(sp) from (select shortestPath(#12:0,#15:2,'BOTH') as sp)

(注意。我正在使用v1.7.4)

答案 2 :(得分:0)

尝试

select expand(shortestPath) from (select shortestPath(" + firstVertex + ", " + secondVertex + "))

您将收到顶点。

相关问题