2013-05-15 49 views
1

我正在使用Neo4j,我不知道是否有可能创建一个独特的领域的lucene索引。 (也就是说,每一个键/值对,可以只用一个节点相关联)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"); 

是否有可能实现类似的东西?

谢谢!

+0

Lucene的没有“节点”的概念(作为图概念)。我不清楚你试图完成什么。 –

+0

我的问题与neo4j索引更相关。我只想知道是否有可能创建一个唯一索引。 – gipouf

+0

如果您的问题与neo4j索引更相关,那么您应该编辑它以从“索引”前删除“lucene”。 – Spaceghost

回答

0

在我的代码我使用的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);