本文整理汇总了Java中org.neo4j.unsafe.batchinsert.BatchInserterIndex类的典型用法代码示例。如果您正苦于以下问题:Java BatchInserterIndex类的具体用法?Java BatchInserterIndex怎么用?Java BatchInserterIndex使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BatchInserterIndex类属于org.neo4j.unsafe.batchinsert包,在下文中一共展示了BatchInserterIndex类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testInsertionSpeed
import org.neo4j.unsafe.batchinsert.BatchInserterIndex; //导入依赖的package包/类
@Ignore
@Test
public void testInsertionSpeed() throws Exception
{
BatchInserter inserter = BatchInserters.inserter( dbRule.getStoreDirAbsolutePath() );
BatchInserterIndexProvider provider = new LuceneBatchInserterIndexProvider( inserter );
BatchInserterIndex index = provider.nodeIndex( "yeah", EXACT_CONFIG );
index.setCacheCapacity( "key", 1000000 );
long t = currentTimeMillis();
for ( int i = 0; i < 1000000; i++ )
{
Map<String, Object> properties = map( "key", "value" + i );
long id = inserter.createNode( properties );
index.add( id, properties );
}
System.out.println( "insert:" + ( currentTimeMillis() - t ) );
index.flush();
t = currentTimeMillis();
for ( int i = 0; i < 1000000; i++ )
{
count( (Iterator<Long>) index.get( "key", "value" + i ) );
}
System.out.println( "get:" + ( currentTimeMillis() - t ) );
}
示例2: testBatchIndexToAutoIndex
import org.neo4j.unsafe.batchinsert.BatchInserterIndex; //导入依赖的package包/类
@Test
public void testBatchIndexToAutoIndex() throws IOException {
BatchInserter inserter = BatchInserters.inserter(new File(path));
BatchInserterIndexProvider indexProvider = new LuceneBatchInserterIndexProvider(inserter);
BatchInserterIndex index =
indexProvider.nodeIndex("node_auto_index", MapUtil.stringMap("type", "exact"));
long node = inserter.createNode(MapUtil.map("foo", "bar"));
index.add(node, MapUtil.map("foo", "bar"));
index.flush();
assertThat("Batch indexed node can be retrieved", index.get("foo", "bar").next(), is(node));
indexProvider.shutdown();
inserter.shutdown();
graphDb = getGraphDb();
try (Transaction tx = graphDb.beginTx()) {
assertThat("AutoIndex is not enabled after reopening the graph", graphDb.index()
.getNodeAutoIndexer().isEnabled(), is(false));
assertThat("AutoIndexed properties are not maintained after closing the graph", graphDb
.index().getNodeAutoIndexer().getAutoIndexedProperties(), is(empty()));
assertThat("Batch index properties are in the index", graphDb.index().getNodeAutoIndexer()
.getAutoIndex().query("foo", "bar").size(), is(1));
tx.success();
}
}
示例3: initValueIndex
import org.neo4j.unsafe.batchinsert.BatchInserterIndex; //导入依赖的package包/类
protected void initValueIndex() throws DMPGraphException {
try {
final Tuple<BatchInserterIndex, BatchInserterIndexProvider> valuesIndexTuple = getOrCreateIndex(GraphIndexStatics.VALUES_INDEX_NAME,
GraphStatics.VALUE, true, 1);
values = valuesIndexTuple.v1();
valuesProvider = valuesIndexTuple.v2();
} catch (final Exception e) {
final String message = "couldn't load indices successfully";
BatchNeo4jProcessor.LOG.error(message, e);
BatchNeo4jProcessor.LOG.debug("couldn't finish writing successfully");
throw new DMPGraphException(message);
}
}
示例4: initStatementIndex
import org.neo4j.unsafe.batchinsert.BatchInserterIndex; //导入依赖的package包/类
private void initStatementIndex() throws DMPGraphException {
try {
final Tuple<BatchInserterIndex, BatchInserterIndexProvider> statementUUIDsIndexTuple = getOrCreateIndex(GraphIndexStatics.STATEMENT_UUIDS_INDEX_NAME, GraphStatics.UUID, false, 1);
statementUUIDs = statementUUIDsIndexTuple.v1();
statementUUIDsProvider = statementUUIDsIndexTuple.v2();
} catch (final Exception e) {
final String message = "couldn't load indices successfully";
BatchNeo4jProcessor.LOG.error(message, e);
BatchNeo4jProcessor.LOG.debug("couldn't finish write TX successfully");
throw new DMPGraphException(message);
}
}
示例5: getOrCreateUserNodeID
import org.neo4j.unsafe.batchinsert.BatchInserterIndex; //导入依赖的package包/类
private static long getOrCreateUserNodeID(final String userid,
final Map<String, Long> usersNodesMap,
final BatchInserterIndex usersIndex,
final BatchInserter inserter,
final Label label) {
long userNodeID;
if (usersNodesMap.containsKey(userid)) {
userNodeID = usersNodesMap.get(userid);
} else {
userNodeID = inserter.createNode(MapUtil.map("node_id", userid), label);
usersNodesMap.put(userid, userNodeID);
usersIndex.add(userNodeID, MapUtil.map("node_id", userid));
}
return userNodeID;
}
示例6: getOrCreateItemNodeID
import org.neo4j.unsafe.batchinsert.BatchInserterIndex; //导入依赖的package包/类
private static long getOrCreateItemNodeID(final String itemid,
final Map<String, Long> itemsNodesMap,
final BatchInserterIndex itemsIndex,
final BatchInserter inserter,
final Label label) {
long itemNodeID;
if (itemsNodesMap.containsKey(itemid)) {
itemNodeID = itemsNodesMap.get(itemid);
} else {
itemNodeID = inserter.createNode(MapUtil.map("node_id", itemid), label);
itemsNodesMap.put(itemid, itemNodeID);
itemsIndex.add(itemNodeID, MapUtil.map("node_id", itemid));
}
return itemNodeID;
}
示例7: getOrCreateRelatinshipID
import org.neo4j.unsafe.batchinsert.BatchInserterIndex; //导入依赖的package包/类
private static long getOrCreateRelatinshipID(final String timestamp,
final long userNodeid,
final long itemNodeid,
final Map<String, Long> relationshipsMap,
final BatchInserterIndex relationshipIndex,
final BatchInserter inserter,
final RelationshipType relType) {
long relationID;
String uniqueRelationID = userNodeid + itemNodeid + timestamp;
if (relationshipsMap.containsKey(uniqueRelationID)) {
relationID = relationshipsMap.get(uniqueRelationID);
} else {
relationID = inserter.createRelationship(userNodeid, itemNodeid, relType,
MapUtil.map("timestamp", timestamp));
relationshipsMap.put(uniqueRelationID, relationID);
relationshipIndex.add(relationID, MapUtil.map("useritem", uniqueRelationID));
}
return relationID;
}
示例8: createIndex
import org.neo4j.unsafe.batchinsert.BatchInserterIndex; //导入依赖的package包/类
public BatchInserterIndex createIndex(String labelName, String pk) {
BatchInserterIndex idx = this.getIndex(labelName);
idx.setCacheCapacity(pk, this.cacheCapacity);
this.counter.put(labelName, this.flushInterval);
this.pkMap.put(labelName, pk);
return idx;
}
示例9: createNode
import org.neo4j.unsafe.batchinsert.BatchInserterIndex; //导入依赖的package包/类
private synchronized void createNode(String labelName, Map<String, Object> properties, BatchInserterIndex idx,
String pk) {
idx.add(this.inserter.createNode(properties, DynamicLabel.label(labelName)),
MapUtil.map(pk, properties.get(pk)));
long n = this.counter.get(labelName);
this.counter.put(labelName, ++n);
if(n % this.flushInterval == 0)
idx.flush();
}
示例10: createBatchIndex
import org.neo4j.unsafe.batchinsert.BatchInserterIndex; //导入依赖的package包/类
/**
* Create and store the index, if it doesn't exist.
*
* @param indexName Name of the index
* @param indexCacheSize Number of element into the cache size for the index
*/
public void createBatchIndex(String indexName, Integer indexCacheSize) {
if (!batchInserterIndexes.containsKey(indexName)) {
BatchInserterIndex index = indexProvider.nodeIndex(indexName, MapUtil.stringMap("type", "exact"));
if (indexCacheSize > 0) {
index.setCacheCapacity(BACTH_INDEX_ID_NAME, indexCacheSize);
}
batchInserterIndexes.put(indexName, index);
} else {
log.trace("Index [" + indexName + "] already exist");
}
}
示例11: flushBatchIndex
import org.neo4j.unsafe.batchinsert.BatchInserterIndex; //导入依赖的package包/类
/**
* Flush the specified index on the disk, so it will be available after for search.
*
* @param indexName Name of the index to flush
*/
public void flushBatchIndex(String indexName) {
if (batchInserterIndexes.containsKey(indexName)) {
BatchInserterIndex index = batchInserterIndexes.get(indexName);
index.flush();
} else {
log.trace("Flushing a non exist index ... [" + indexName + "]");
}
}
示例12: indexNodeInBatchIndex
import org.neo4j.unsafe.batchinsert.BatchInserterIndex; //导入依赖的package包/类
/**
* Push a node importId into the batch index.
*
* @param indexName The batch index name
* @param node Neo4j identifier
* @param importIdValue Import identifier
*/
public void indexNodeInBatchIndex(String indexName, long node, Object importIdValue) {
if (batchInserterIndexes.containsKey(indexName)) {
BatchInserterIndex index = batchInserterIndexes.get(indexName);
Map<String, Object> props = new HashMap<>();
props.put(BACTH_INDEX_ID_NAME, importIdValue);
index.add(node, props);
} else {
log.trace("Can't index node " + node + "/" + importIdValue + " into a none existant index [" + indexName + "]");
}
}
示例13: batchInsert
import org.neo4j.unsafe.batchinsert.BatchInserterIndex; //导入依赖的package包/类
@Test
public void batchInsert() throws Exception
{
Neo4jTestCase.deleteFileOrDirectory( new File(
"target/neo4jdb-batchinsert" ) );
// START SNIPPET: batchInsert
BatchInserter inserter = BatchInserters.inserter( "target/neo4jdb-batchinsert" );
BatchInserterIndexProvider indexProvider =
new LuceneBatchInserterIndexProvider( inserter );
BatchInserterIndex actors =
indexProvider.nodeIndex( "actors", MapUtil.stringMap( "type", "exact" ) );
actors.setCacheCapacity( "name", 100000 );
Map<String, Object> properties = MapUtil.map( "name", "Keanu Reeves" );
long node = inserter.createNode( properties );
actors.add( node, properties );
//make the changes visible for reading, use this sparsely, requires IO!
actors.flush();
// Make sure to shut down the index provider as well
indexProvider.shutdown();
inserter.shutdown();
// END SNIPPET: batchInsert
GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase( "target/neo4jdb-batchinsert" );
try ( Transaction tx = db.beginTx() )
{
Index<Node> index = db.index().forNodes( "actors" );
Node reeves = index.get( "name", "Keanu Reeves" ).next();
assertEquals( node, reeves.getId() );
}
db.shutdown();
}
示例14: createLegacyNodeIndex
import org.neo4j.unsafe.batchinsert.BatchInserterIndex; //导入依赖的package包/类
/**
*
* @param neo4ArtLegacyIndex
* @param cacheKey
* @param cacheSize
* @return
*/
public static void createLegacyNodeIndex(Neo4ArtLegacyIndex neo4ArtLegacyIndex, String cacheKey, int cacheSize)
{
BatchInserterIndexProvider batchInserterIndexProvider = getBatchInserterIndexProviderInstance();
BatchInserterIndex index = batchInserterIndexProvider.nodeIndex(neo4ArtLegacyIndex.getName(), getLegacyNodeIndexConfig(neo4ArtLegacyIndex.getType()));
if (cacheSize != 0)
{
index.setCacheCapacity(cacheKey, cacheSize);
}
}
示例15: getFromLegacyNodeIndex
import org.neo4j.unsafe.batchinsert.BatchInserterIndex; //导入依赖的package包/类
/**
* TODO it's not necessary to provide key and value: we could also just pass a Node 'cause we already know the key (defined at index creation time)
*
* @param indexName
* @param key
* @param value
* @return
*/
public static IndexHits<Long> getFromLegacyNodeIndex(Neo4ArtLegacyIndex neo4ArtLegacyIndex, String key, Object value)
{
BatchInserterIndex batchInserterIndex = getBatchInserterIndexProviderInstance().nodeIndex(neo4ArtLegacyIndex.getName(), getLegacyNodeIndexConfig(neo4ArtLegacyIndex.getType()));
if (batchInserterIndex == null)
{
throw new IllegalArgumentException("Index " + neo4ArtLegacyIndex.getName() + " doesn't exists. You must create it before getting something from it.");
}
return batchInserterIndex.get(key, value);
}