如何在OrientDB中找到最短路径长度? 有很多例子可以找到最短的路径,但必须有办法只获得这条路径的长度?
而不是顶点列表like with this query
SELECT expand(path) FROM (
SELECT shortestPath($from, $to) AS path
LET
$from = (SELECT FROM Profiles WHERE Name='Santo' and Surname='OrientDB'),
$to = (SELECT FROM Countries WHERE Name='United States')
UNWIND path
)
我只想要一个数字。
我使用Java来查询数据库,因此Java API函数也可以。
答案 0 :(得分:1)
试试这个:
SELECT sum(path.size()) FROM (
SELECT shortestPath($from, $to) AS path
LET
$from = (SELECT FROM Profiles WHERE Name='Santo' and Surname='OrientDB'),
$to = (SELECT FROM Countries WHERE Name='United States')
UNWIND path
)
希望它有所帮助。
此致