OrientDB 使用 shortestPath() 获取边

标签 orientdb orientjs

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

最佳答案

您可以使用 javascript 函数。

我用过这些记录

enter image description here

enter image description here

我用了这个代码

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;

enter image description here

希望能帮助到你。

关于OrientDB 使用 shortestPath() 获取边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36794694/

相关文章:

OrientDB:列出所有索引

express - orientjs 和 expressjs 4 集成

javascript - 将多个查询呈现到同一个 jade 模板

orientdb - 你如何使用orientjs做一个 'Insert if not exists'?

node.js - OrientJS:将二进制数据与 "normal"属性一起存储

javascript - 在 OrientDB 中嵌入函数中的记录

java - 导入 Java OrientDB 包

neo4j - Apache Samza 本地存储 - OrientDB/Neo4J 图而不是 KV 存储

orientdb - 关于OrientDB设计的一些问题

node.js - 使用 OrientJS 模块连接到 NodeJS 中的 OrientDB -- "Socket Closed"错误