0

我有一个密集节点问题,为了解决这个问题,我一直在使用索引来使用本机 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?

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

4

1 回答 1

2

是的,在 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(除非有一个指向它的指针 from n)。

于 2013-06-25T21:31:35.603 回答