Database Reference
In-Depth Information
ods to select which relationships to expand, resulting in code that's much clearer and more
concise. The following snippet shows how you can update the traversal from listing 8.3 to
use this syntax. A portion of the code from listing 8.3 has been omitted for clarity:
In this snippet, you use the TraversalDescription.relationships(...)
method to add the relationship types you want to expand . Because StandardEx-
pander is used by default, this will result in exactly the same code being executed under
the hood as for the code in listing 8.3 , with slightly more concise syntax.
The code in listing 8.3 looks much more like the code you used for traversals earlier in the
book, but you now know that behind it is the StandardExpander in action. Using the
TraversalDescription.expand(...) method, you can have control over which
expander is used for any traversal, which is the flexibility we'll be taking advantage of in
the following sections.
In the next two sections, you're going to learn how to use nondefault expander implement-
ations in your traversals. First, let's start with ordered relationship expanders.
8.2.2. Ordering relationships for expansion
As you've seen, StandardExpander has a limitation—the order of the relationships to
be expanded is fixed, and it uses the order in which the relationships were created. In most
casesthisisareasonablelimitation,asmosttraversalstreateachrelationshiptypethesame
way. But in some scenarios it would be preferable to expand relationships in a particular
order. Let's use the same graph as in the previous section ( figure 8.4 ) to demonstrate the
use case for ordering relationships.
Just as in the previous section, we'll find all movies that any of John's direct contacts liked
(including both friends and work colleagues). This time, we'll prefer the movies liked by
Search WWH ::




Custom Search