Database Reference
In-Depth Information
Note
In order to understand the preceding code, follow the comments provided within the code.
This needs to be followed for the other Java code snippets given in this chapter.
Next, extending the same example, let's populate an index for relationships and add the
following code snippet just before tx.success(); :
// Creating new node and Adding Label and properties
Node movieNode = graphDb.createNode();
movieNode.addLabel(DynamicLabel.label("Movie"));
movieNode.setProperty("Title", "The Karate Kid II");
// Define a relationship Type
DynamicRelationshipType actsIn =
DynamicRelationshipType.withName( "ACTS_IN" );
//Create a relationship between Actor and Movie
//and define its property
Relationship role1 = node.createRelationshipTo( movieNode,
actsIn);
role1.setProperty( "Role", "Daniel LaRusso" );
rolesIndex.add(role1, "Role",role1.getProperty( "Role" ) );
The next step is to search the legacy indexes. Legacy API provides the following kinds of
searches:
Exact search : This allows us to search for the exact key-value pair
Search for more than 1 key value pair : This allows us to search with * or ? .
Full text : Legacy index API extends Lucene APIs, so it also provides full text
searches
Continuing with the same example, add the following code snippet just before
tx.success(); for searching nodes:
//Search the ActorsIndex by using the exact Match of Key
and value
IndexHits<Node> hits = actorsIndex.get( "Name", "Ralph
Macchio" );
Node searchNode = hits.next();
System.out.println("Node ID = "+searchNode.getId()+", Name
= "+searchNode.getProperty("Name"));
Search WWH ::




Custom Search