假设两个节点之间存在如下关系
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
调用。