简体   繁体   English

使用Scala在Neo4j中建立索引关系

[英]Indexing relationships in Neo4j using Scala

Say that there is a relationship between 2 nodes as below 假设两个节点之间存在如下关系

start --> "follows" --> end

I want to create an index named "Relations" and add the above relation to the index. 我想创建一个名为“ Relations”的索引,并将上述关系添加到索引中。 How do I do that in Scala or in Java? 如何在Scala或Java中做到这一点?

I tried doing it this way : 我试图这样做:

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)

But, am getting Type mismatch error. 但是,正在收到类型不匹配错误。

You should probably use the relation index instead of the node index, like 您可能应该使用关系索引而不是节点索引,例如

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))

NOTE: I removed the index.get call and used a "safer" foreach call on the optional value. 注意:我删除了index.get调用,并对可选值使用了“更安全”的foreach调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM