OrientDB:仅遍历一些 属性 的边
OrientDB: traverse only edges with some property
我想从一个顶点开始遍历,只跟随与特定表达式匹配的边(例如:friendsWith.type="bestFriend"
)。我该怎么做呢?
此外,我还得运行对一堆顶点进行这个操作。是否可以通过 "head" 遍历来组织事物?理想情况下 return 将是:
[[start1, [list of all the vertices during traversal], [start2, [...]],...]
试试这个:
select outV().name as start, inV().name as end from(traverse * from friendsWith while type = "bestFriend")
不用遍历也能做到
希望对您有所帮助。
此致。
我试过这张图
我用这个 javascript 函数和参数 rid
var g=orient.getGraph();
var nodes = [];
var previous=[];
var currently=[];
var b=g.command("sql","select from " + rid);
if(b.length>0){
var vertex=b[0];
previous.push(vertex);
nodes.push(vertex);
do{
for(i=0;i<previous.length;i++){
var vertexOut=previous[i];
var edges=g.command("sql","select expand(outE('friendsWith')) from "+ vertexOut.getId());
for(s=0;s<edges.length;s++){
var edge=edges[s];
var type= edge.getProperty("type");
if(type=="bestFriend"){
var vertices=g.command("sql","select expand(inV('friendsWith')) from "+ edge.getId());
var vertex=vertices[0];
var found=false;
for(k=0;k<nodes.length;k++){
var id=nodes[i].getId();
var id_v=vertex.getId()
if(id==id_v){
found=true;
break;
}
}
if(found==false){
currently.push(vertex);
nodes.push(vertex);
}
}
}
}
change();
}while(previous.length>0);
return nodes;
}
function change(){
previous=[];
for (indice=0;indice<currently.length;indice++)
previous.push(currently[indice]);
currently=[];
}
并且 select expand(node) from (select myFunction("#9:0") as node)
我得到了
希望对您有所帮助。
我想从一个顶点开始遍历,只跟随与特定表达式匹配的边(例如:friendsWith.type="bestFriend"
)。我该怎么做呢?
此外,我还得运行对一堆顶点进行这个操作。是否可以通过 "head" 遍历来组织事物?理想情况下 return 将是:
[[start1, [list of all the vertices during traversal], [start2, [...]],...]
试试这个:
select outV().name as start, inV().name as end from(traverse * from friendsWith while type = "bestFriend")
不用遍历也能做到
希望对您有所帮助。
此致。
我试过这张图
我用这个 javascript 函数和参数 rid
var g=orient.getGraph();
var nodes = [];
var previous=[];
var currently=[];
var b=g.command("sql","select from " + rid);
if(b.length>0){
var vertex=b[0];
previous.push(vertex);
nodes.push(vertex);
do{
for(i=0;i<previous.length;i++){
var vertexOut=previous[i];
var edges=g.command("sql","select expand(outE('friendsWith')) from "+ vertexOut.getId());
for(s=0;s<edges.length;s++){
var edge=edges[s];
var type= edge.getProperty("type");
if(type=="bestFriend"){
var vertices=g.command("sql","select expand(inV('friendsWith')) from "+ edge.getId());
var vertex=vertices[0];
var found=false;
for(k=0;k<nodes.length;k++){
var id=nodes[i].getId();
var id_v=vertex.getId()
if(id==id_v){
found=true;
break;
}
}
if(found==false){
currently.push(vertex);
nodes.push(vertex);
}
}
}
}
change();
}while(previous.length>0);
return nodes;
}
function change(){
previous=[];
for (indice=0;indice<currently.length;indice++)
previous.push(currently[indice]);
currently=[];
}
并且 select expand(node) from (select myFunction("#9:0") as node)
我得到了
希望对您有所帮助。