Database Reference
In-Depth Information
Listing 3.11. Finding nodes with a given label and property
By default, the lookup for nodes by label and property is performed by brute force by the
Neo4j engine (by iterating all through all nodes with the given label, and comparing the
required property name and value). But if a schema index is defined on label and property,
the Neo4j engine will use the much faster index lookup. We'll discuss using schema in-
dexes in chapter 5 .
Note
Asyousawin listing 3.10 , findingallnodeswithagivenlabelisconsideredagraph-global
operation (as by design it can fetch large parts of the graph), so the operation is available
via the GlobalGraphOperations class. On the other hand, finding all nodes by label
and property ( listing 3.11 ) is exposed via the GraphDatabaseService interface, be-
cause it's expected to return a small proportion of nodes in the graph.
Labels are a nice addition to Neo4j, and not only as a typing strategy. Because nodes can
havemultiplelabels,youcancreatelabelstogroupnodesthatareoftenusedtogether(even
with different types), without the need to use properties. For example, RED_THINGS (for
all nodes that are red), FLYING (for all nodes that represent things that can fly), and so on.
3.4. Summary
In the first part of this chapter, we showed how you could model the requirements for a
movie-lovers' social network example. You modeled the requirements using a set of dia-
grams, or a virtual whiteboard, just as you'd approach application design in the software
development process.
In the second part of this chapter, we demonstrated step by step how you could create that
same graph model in the Neo4j graph database using the Neo4j Core Java API.
 
Search WWH ::




Custom Search