簡體   English   中英

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

[英]Indexing relationships in Neo4j using Scala

假設兩個節點之間存在如下關系

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調用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM