假设两个节点之间存在如下关系
start --> "follows" --> end
我想创建一个名为“Relations”的索引,并将上述关系添加到该索引中。我如何在 Scala 或 Java 中做到这一点?
我尝试这样做:
override def NodeIndexConfig = ("Relations", Some(Map("provider" -> "lucene", "type" -> "fulltext")))::NIL
val rel_name = group+"_Voteup"
val relation = user_node --> rel_name --> item_node
val Relation_Index = getNodeIndex("Relations").get
val rel_value = user_id+item_id+rel_name
Relation_Index += (relation,"rel_id",rel_value)
但是,我收到类型不匹配错误。
最佳答案
您可能应该使用关系索引而不是节点索引,例如
override def RelationIndexConfig = ("Relations", Some(Map("provider" -> "lucene", "type" -> "fulltext")))::Nil
val rel_name = group+"_Voteup"
val relation = user_node --> rel_name --> item_node
val Relation_Index = getRelationIndex("Relations")
val rel_value = user_id+item_id+rel_name
Relation_Index.foreach(_ += (relation,"rel_id",rel_value))
注意:我删除了 index.get
调用,并对可选值使用了“更安全”的 foreach
调用。
关于java - 使用 Scala 在 Neo4j 中建立索引关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15806546/