【问题标题】:Performing match by index lookup with cypher使用密码按索引查找执行匹配
【发布时间】:2013-06-25 18:46:52
【问题描述】:

我有一个密集节点问题,为了解决这个问题,我一直在使用索引来使用本机 Java API 执行一些匹配,但我一直在给 Cypher 再看一遍,想知道这是否可以完成。目前我的模式在 Java 代码中如下所示:

Node startNode = db.getNodeById(1);
Index<Relationship> relationshipIndex = db.index.forRelationships("relationships");

for(Relationship relationship1 : startNode.getRelationships(Direction.OUT)) {
    Node otherNode = relationship.getOtherNode(startNode);
    String indexValue = (String)otherNode.getProperty("indexValue");
    for(Relationship relationship2 : relationshipIndex.get("indexKey", indexValue)){
        Node endNode = relationship.getOtherNode(startNode);
        //Processing on the endNode
    }
}

我如何将它翻译成密码?比如:

START startNode=node(1)
MATCH startNode-[r1]->otherNode
WITH node:relationships("indexValue:" + otherNode.indexValue) as r2
RETURN r2.endNode //Notation for getting node off relationship?

我真的没有看到任何地方只是获得关系,然后通过这样的关系获得结束节点。

【问题讨论】:

    标签: neo4j cypher


    【解决方案1】:

    是的,在 2.0 中有一个 startNode(rel)/endNode(rel) 函数,但在 1.9 或更早版本中没有。

    http://console.neo4j.org/r/4807s7

    所以理论上你可以这样做:

    start rel=rel:rel_auto_index(indexKey="value") 
    with endNode(rel) as n
    match n-->m
    return *
    

    这将避免接触关系的 startNode(除非有一个从 n 指向它的指针)。

    【讨论】:

    • 你能在开始之外进行索引查找吗?我更新了我的代码以显示我的意思,但我对第一部分进行了遍历,然后是关系索引查找。
    • 显然不是。实际上有一个功能请求:github.com/neo4j/neo4j/issues/93github.com/neo4j/neo4j/issues/389
    • 这就是我的假设,我再次更新了问题以反映在 Cypher 中我想要的那种,但看起来未解决的问题也想要我所要求的。
    猜你喜欢
    • 1970-01-01
    • 2017-02-23
    • 2018-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-10
    • 1970-01-01
    相关资源
    最近更新 更多