Skip to content

Instantly share code, notes, and snippets.

@peterneubauer
Created October 18, 2012 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterneubauer/3911804 to your computer and use it in GitHub Desktop.
Save peterneubauer/3911804 to your computer and use it in GitHub Desktop.
Neo4j auto index and batch inserter
public void shouldCreateAutoIndex() throws Exception
{
String path = new File( PATH, "10" ).getAbsolutePath();
BatchInserter inserter = new BatchInserterImpl( path );
BatchInserterIndexProvider provider = new LuceneBatchInserterIndexProviderNewImpl(
inserter );
BatchInserterIndex index = provider.nodeIndex( "node_auto_index", EXACT_CONFIG );
long id = inserter.createNode( null );
Map<String, Object> props = new HashMap<String, Object>();
props.put( "name", "peter" );
index.add( id, props );
index.flush();
provider.shutdown();
inserter.shutdown();
GraphDatabaseService db = new GraphDatabaseFactory().
newEmbeddedDatabaseBuilder( path ).
setConfig( GraphDatabaseSettings.node_keys_indexable, "name" ).
setConfig( GraphDatabaseSettings.relationship_keys_indexable, "relProp1,relProp2" ).
setConfig( GraphDatabaseSettings.node_auto_indexing, "true" ).
setConfig( GraphDatabaseSettings.relationship_auto_indexing, "true" ).
newGraphDatabase();
Transaction tx = db.beginTx();
try
{
// Create the primitives
Node node1 = db.createNode();
// Add indexable and non-indexable properties
node1.setProperty( "name", "bob" );
// Make things persistent
tx.success();
}
catch ( Exception e )
{
tx.failure();
}
finally
{
tx.finish();
}
assertTrue(db.index().getNodeAutoIndexer().getAutoIndex().get( "name", "peter" ).hasNext());
assertTrue(db.index().getNodeAutoIndexer().getAutoIndex().get( "name", "bob" ).hasNext());
assertFalse(db.index().getNodeAutoIndexer().getAutoIndex().get( "name", "joe" ).hasNext());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment