Integrated index usage

This example is similar to the basic indexing example, but uses the integrated indexing API.

Take a look at the differences. Here's creating an index:

        graphDb = new EmbeddedGraphDatabase( DB_PATH );
        nodeIndex = graphDb.index().forNodes( INDEX_NAME );
        registerShutdownHook();

A new node index is created by requesting the named index from the index() singleton associated with a GraphDatabaseService. If the index does not yet exist, it will be created.

Indexing a node's property is easy:

        Node node = graphDb.createNode();
        node.setProperty( USERNAME_KEY, username );
        nodeIndex.add( node, USERNAME_KEY, username );

The nicest improvement is that the index does not require a seperate shutdown. Just shutdown the GraphDatabaseService:

        graphDb.shutdown();

Full source code: UsingIntegratedIndex