2013-06-25 29 views
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? 

我真的沒有看到任何地方只是得到一個關係,然後通過像這樣的關係得到最終節點。

回答

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(除非有一個指針回從n)。

+0

你可以在開始之外做索引查找嗎?我已更新我的代碼以顯示我的意思,但我在第一部分進行遍歷,然後進行關係索引查找。 – Nicholas

+0

顯然不是。實際上有一個功能請求:https://github.com/neo4j/neo4j/issues/93和https://github.com/neo4j/neo4j/issues/389 –

+0

這就是我所設想的,我更新了問題再次反映Cypher類型的我想要的,但是看起來公開的問題也想要我所要求的。 – Nicholas