【问题标题】:Iterate Cypher results in Scala在 Scala 中迭代 Cypher 结果
【发布时间】:2013-11-20 20:46:36
【问题描述】:

我正在使用带有刻度的 Neo4j 1.9。 运行此代码时,我在第 5 行出现错误,并显示以下消息: java.lang.ClassCastException: scala.collection.immutable.Stream$Cons 不能转换为 org.neo4j.graphdb.Node

这是我的代码:

 val _shortestPathQuery= """
    START n=node:node_auto_index(tag="body"),m=node:node_auto_index(tag="#text")
    MATCH p=shortestPath( n-[r:FATHER*..]-m )
    WHERE m.text =~ '.*%s.*'
    RETURN NODES(p) as pathnodes;
    """.stripMargin.format(toSearch)

    val tx = graphDb.beginTx()
    val result = engine.execute( _shortestPathQuery )

    val decPath:Iterator[org.neo4j.graphdb.Node]  = result.columnAs("pathnodes")

    for ( node:org.neo4j.graphdb.Node <- decPath)
    {
       println(node + ": " + node.getProperty("nodeid") + " " + node.getId)
    }

我找到了很多 java 代码,但我无法在 Scala 中进行转换。

如果我打印结果: println(result.dumpToString()) 我会看到正确的行。

非常感谢

【问题讨论】:

    标签: scala neo4j


    【解决方案1】:

    您返回一个包含 Iterable 个节点的列。

    所以也许使用:

    val _shortestPathQuery= """
        START n=node:node_auto_index(tag="body"),m=node:node_auto_index(tag="#text")
        MATCH p=shortestPath( n-[r:FATHER*..]-m )
        WHERE m.text =~ '.*%s.*'
        RETURN NODES(p) as pathnodes;
        """.stripMargin.format(toSearch)
    
        val tx = graphDb.beginTx()
        val result = engine.execute( _shortestPathQuery )
    
        val decPath:Iterator[Iterator[org.neo4j.graphdb.Node]]  = result.columnAs("pathnodes")
    
        for ( node:org.neo4j.graphdb.Node <- nodes <- decPath )
        {
           println(node + ": " + node.getProperty("nodeid") + " " + node.getId)
        }
    

    【讨论】:

    • 非常感谢迈克尔
    猜你喜欢
    • 1970-01-01
    • 2016-07-11
    • 2011-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多