1

我正在使用 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");

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

谢谢!

4

2 回答 2

0

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

于 2013-06-10T11:28:05.120 回答
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);
于 2013-06-10T15:12:19.207 回答