OrientDB 使用 shortestPath() 获取边 [英] OrientDB get Edges with shortestPath()

查看:58
本文介绍了OrientDB 使用 shortestPath() 获取边的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于 OrientDB 的 shortestPath() 函数的问题.如果我针对 OrientDB 查询 select shortestPath('#9:1', '#15:1', 'BOTH') 我只会得到路径的顶点.但我也想要它们之间的边缘.如何同时选择顶点和边?

I have a Question about the shortestPath() Function of OrientDB. If I Query select shortestPath('#9:1', '#15:1', 'BOTH') against a OrientDB I just get the Vertex of the Path. But I also want the Edges between them. How can I SELECT both, the Vertex and the Edges?

推荐答案

您可以使用 javascript 函数.

You can use a javascript function.

我用过这些记录

我用过这个代码

var g=orient.getGraph();
var b=g.command("sql","select expand(shortestPath(" + start + "," + end + ", 'BOTH'))");
var list=[];
for(i=0;i<b.length-1;i++){
    var rid1=b[i].getId(); 
    var rid2=b[i+1].getId(); 
    var query="select from e where out = " + rid1 + " and in = " + rid2 + " limit 1";
    var edge=g.command("sql",query);
    list.push(b[i]);
    list.push(edge[0]);
    if(i==b.length-2){
        list.push(b[i+1]);
    }
}
return list;

希望有帮助.

这篇关于OrientDB 使用 shortestPath() 获取边的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆