2013-05-15 53 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);