Question

I'm currently trying Neo4J Koan Tutorial. I'm getting really confused at Koan06 where Traversal are introduced. Method Node.traversal is deprecated in favour for Traversal.traverse. As I tried it, I saw, that the whole Traversal class is deprecated, too. I read the docs to find out what I'm supposed to use, but can't find anything. The docs didn't even mention that Traversal is deprecated (of course Traversal methods like traverse and description are deprecated without clearification, too).

Simple question: What am I supposed to use to build a TraversalDescription?

Was it helpful?

Solution

Neo4j Traversers are built by the Traversal class under the hood, whose configuration is made available as TraversalDescription via the GraphDatabaseService (in Neo4j 2.0).

I believe that there are still legacy, deprecated implementations in the code of Neo4J.

Traversal comes in 2 types:

1. Unidirectional traversal

Instantiate by calling:

TraversalDescription traversalDescription = graphDatabaseService.traversalDescription()

The obtained traversalDescription is actually a builder pattern allowing you to set different properties for your traversal. See the API at http://api.neo4j.org/current/org/neo4j/graphdb/traversal/TraversalDescription.html.

2. Bi-directional traversal

A bi-directional traversal is instantiated using

BidirectionalTraversalDescription bidirectionalTraversalDescription = 
      graphDatabaseService.bidirectionalTraversalDescription()

This TraversalDescription has a start and endside which are actually two different TraversalDescriptions and can be instantiated using a similar building pattern as the uni-directional traversal.

e.g.

graphDatabaseService
  .bidirectionalTraversalDescription()
    .startSide(graphDatabaseService
      .traversalDescription()
      .depthFirst()
      .uniqueness(Uniqueness.NODE_PATH))
    .endSide(graphDatabaseService
      .traversalDescription()
      .depthFirst()
      .uniqueness(Uniqueness.NODE_PATH))

I used Scala code to show the instantiations, I hope it is clear.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top