Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用scala检索与给定节点相关的neo4j节点_Scala_Neo4j - Fatal编程技术网

使用scala检索与给定节点相关的neo4j节点

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

我有两个节点,分别名为User\u node和Article\u node,它们通过关系进行关联

文章节点->作者->用户节点


如何获取由给定用户节点编写的所有文章节点?

我假设您使用的是嵌入式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))