使用scala检索与给定节点相关的neo4j节点
我有两个节点,分别名为User\u node和Article\u node,它们通过关系进行关联 文章节点->作者->用户节点使用scala检索与给定节点相关的neo4j节点,scala,neo4j,Scala,Neo4j,我有两个节点,分别名为User\u node和Article\u node,它们通过关系进行关联 文章节点->作者->用户节点 如何获取由给定用户节点编写的所有文章节点?我假设您使用的是嵌入式neo4j,因此有一个类型为org.neo4j.graphdb.node的对象。Node的方法getRelationships具有多个重载,但采用RelationshipType的varargs的方法应该适合您。要将所有节点对象连接到起始节点,必须编写类似以下内容(未测试): // we use scala
如何获取由给定用户节点编写的所有文章节点?我假设您使用的是嵌入式neo4j,因此有一个类型为org.neo4j.graphdb.node的对象。Node的方法getRelationships具有多个重载,但采用RelationshipType的varargs的方法应该适合您。要将所有节点对象连接到起始节点,必须编写类似以下内容(未测试):
// 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))
我假设您使用的是嵌入式neo4j,因此有一个org.neo4j.graphdb.Node类型的对象。Node的方法getRelationships具有多个重载,但采用RelationshipType的varargs的方法应该适合您。要将所有节点对象连接到起始节点,必须编写类似以下内容(未测试):
// 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))