OrientDB:仅遍历具有某些属性的边

时间:2016-10-26 02:23:20

标签: orientdb

我想从一个顶点遍历,只跟随与特定表达式匹配的边(例如:friendsWith.type="bestFriend")。我该怎么做呢?

此外,我必须为一堆顶点运行此操作。是否可以通过" head"遍历?理想情况下,回报将是:

[[start1, [list of all the vertices during traversal], [start2, [...]],...]

2 个答案:

答案 0 :(得分:1)

我尝试使用此图

enter image description here

我在参数rid

中使用了这个javascript函数
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)我得到了

enter image description here

希望它有所帮助。

答案 1 :(得分:0)

试试这个:

select outV().name as start, inV().name as end from(traverse * from friendsWith while type = "bestFriend")

即使没有遍历,你也可以做到。

希望它有所帮助。

问候。