Created
October 18, 2012 13:28
-
-
Save peterneubauer/3911804 to your computer and use it in GitHub Desktop.
Neo4j auto index and batch inserter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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