【问题标题】:Neo4j/Lucene - How to create a unique index?Neo4j/Lucene - 如何创建唯一索引?
【发布时间】:2013-05-10 09:05:07
【问题描述】:

我正在使用 Neo4j,我想知道是否可以创建具有唯一字段的 lucene 索引。 (即每个键值对只能关联一个节点)

例如,我想实现以下行为:

someIndex.add(node1, "firstName", "Roy");
someIndex.add(node2, "firstName", "John");

// Here I expect to recieve an exception because the key/value pair (firstName, Roy) is already associated with node1
someIndex.add(node3, "firstName", "Roy");

有没有可能实现这样的目标?

谢谢!

【问题讨论】:

  • Lucene 没有“节点”的概念(作为图形概念)。我不太清楚你想完成什么。
  • 我的问题与 neo4j 索引有关。我只想知道是否可以创建唯一索引。
  • 如果您的问题与 neo4j 索引更相关,那么您应该编辑它以从“index”前面删除“lucene”。

标签: lucene indexing neo4j


【解决方案1】:

在 Java API 级别上,您可以使用 UniqueFactory。用法示例,请查看http://docs.neo4j.org/chunked/stable/transactions-unique-nodes.html

【讨论】:

    【解决方案2】:

    在我的代码中,我使用 BatchInserterIndex 并添加我需要索引的键和值的映射。 代码是这样的:

    BatchInserterIndex myIndex = indexProvider.nodeIndex("myIndex", MapUtil.stringMap("type", "exact"));
    Map<String, Object> key_Value_IndexMap = new ConcurrentHashMap<String, Object>();
    key_Value_IndexMap.put("ID", value);
    myIndex.add(createdNodeId, key_Value_IndexMap);
    

    【讨论】:

      猜你喜欢
      • 2015-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多