2
與給定節點檢索Neo4j的節點I有一個名爲User_node和Article_node 2個節點其由關係相關使用階
article_node - > 「Written_By」 - > user_node
我如何獲得由給定用戶節點編寫的所有文章節點?
與給定節點檢索Neo4j的節點I有一個名爲User_node和Article_node 2個節點其由關係相關使用階
article_node - > 「Written_By」 - > user_node
我如何獲得由給定用戶節點編寫的所有文章節點?
我假設你使用的是嵌入式的Neo4j,從而有org.neo4j.graphdb.Node
類型的對象。 Node
有方法getRelationships
有幾個重載,但需要的RelationshipType
可變參數的一個應該爲你工作。可以連接到你的起始節點的所有Node
對象,你會寫這樣的事情(未測試):
// we use scala, so let's make our code pretty ;-)
import collection.JavaConverters._
val author = db.getNodeById(nodeId)
// getRelationships returns an Iterable[Relationship]
val rels = author.getRelationships(DynamicRelationshipType.withName("Written_By"))
// get the article node from the Relationship object
val articles = rels.asScala.map(_.getOtherNode(author))
它的工作。謝謝 :) – yAsH 2013-03-22 09:24:43