Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Graph Neo4j/Gremlin/Cypher:如何在类似地图的设置中获取所有节点,直到达到某个距离(深度)?_Graph_Neo4j_Cypher - Fatal编程技术网

Graph Neo4j/Gremlin/Cypher:如何在类似地图的设置中获取所有节点,直到达到某个距离(深度)?

Graph Neo4j/Gremlin/Cypher:如何在类似地图的设置中获取所有节点,直到达到某个距离(深度)?,graph,neo4j,cypher,Graph,Neo4j,Cypher,我有一个带字段的简单图表-每个字段有4个邻居(东北-西南): 我设置了一个graph db(neo4j),这样它们都很好并且相互连接(就像一个网格)。我现在要做的是从一个起始节点获取所有节点,即5个跃点之外的节点 对于经典的遍历,它可以很好地工作,如下所示: public Collection<Field> getFieldsWithDepth(Field startField, final int depth) { Node fieldNode = this

我有一个带字段的简单图表-每个字段有4个邻居(东北-西南):

我设置了一个graph db(neo4j),这样它们都很好并且相互连接(就像一个网格)。我现在要做的是从一个起始节点获取所有节点,即5个跃点之外的节点

对于经典的遍历,它可以很好地工作,如下所示:

public  Collection<Field> getFieldsWithDepth(Field startField, final int depth) {       
    Node fieldNode = this.getGraphdb().getNodeById(startField.getId());
    Traverser traverser = fieldNode.traverse(Traverser.Order.BREADTH_FIRST, // check direct relations first, then go deeper 
            new StopEvaluator() {

                @Override
                public boolean isStopNode(TraversalPosition pos) {
                    if (pos.depth()==depth)
                        return true;
                    else
                        return false;
                }
            },  // worst case: go to end of graph 
            new ReturnableEvaluator() {

                @Override
                public boolean isReturnableNode(TraversalPosition pos) {
                    return true;
                }
            },
            Relations.north,    
            Direction.OUTGOING,
            Relations.east,
            Direction.OUTGOING,
            Relations.west,
            Direction.OUTGOING,
            Relations.south,
            Direction.OUTGOING
            );

    ArrayList<Field> fields = new ArrayList<Field>();
    for (Node node : traverser.getAllNodes())
    {
        fields.add((Field)this.getGraph().get(node));
    }
    return fields;
}
  1   2   | 3|   4    5 
  6  |7|  | 8| | 9|  10
|11| |12| *13* |14| |15|
 16  |17| |18| |19|  20
 21   22  |23|  24   25 
我用起始节点“13”和“深度”2进行查询,我需要得到标记的12个节点,因为它们距离13有2步之遥

我用了jo4neo这个

如何在cypher或gremlin中实现相同的功能

我找到了friend of friend的示例,但这并没有真正帮助我,因为我需要深度作为参数(即,在某些情况下,我希望深度为4,有时为6)

注意:除了字段之外,还有其他连接,但我显然只需要字段。我还需要得到所有连接的节点,而不仅仅是一个方向

解决方案:多亏了指针,我得到了解决方案:

start n=node(13) match n-[*1..2]->b where b.__type__ = "model.Field" return distinct b

如果您只需要3个步骤:

MATCH a-[:FRIEND*3..3]->x

希望这有帮助

如何找到深度级别?意思是,
*1..3
显示“A->B,A->B->C&A->B->C->D”作为Andres的密码查询的结果,我想找到什么深度计数,即A->B的情况下为1;2在A->B->C等情况下。

谢谢。。。这给我指明了一个正确的方向。。。但是,由于我有多个关系(北/东/南/西)-我可以只使用“匹配a-[:北*1..3,:南*1..3,…]->x”来获取所有连接的关系吗?链接是死的。有人能提供这个小精灵版本吗?
START a=node(3)
MATCH a-[:FRIEND*1..3]->x
RETURN a,x
MATCH a-[:FRIEND*3..3]->x