Database Reference
In-Depth Information
Figure 5.1 shows that a node index such as this can be thought of as a value entry that
relatestooneormorepointerstonodes.Inthiscase,we'reexpectingemailaddressestobe
unique, so we expect one primary email address for each user.
Figure 5.1. Index pointing to user nodes as values, using the email property as a key
In Neo4j, the IndexManager provides access to the index using a simple string as the
index key. In our social networking application, a common starting point will be a user. To
uniquely identify users, you'll have them use their email addresses to log in. The code in
listing 5.1 shows the creation of a new user and the creation of an index entry. This means
you can quickly find the node representing the user via the email address. All available
index operations are defined on the Index<Node> interface, an instance of which is ac-
cessed from Neo4j's index manager component:
IndexManager indexManager = graphDB.index();
Index<Node> userIndex = indexManager.forNodes("users");
Note that you simply ask the Neo4j index manager component for the index with the re-
quired name. From the perspective of the code, it's irrelevant whether the index exists; if it
doesn't exist, the index will be created when you ask for it.
 
Search WWH ::




Custom Search