Neo4j which Traversal should one use?
Asked Answered
F

1

7

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?

Frisbee answered 22/1, 2014 at 16:36 Comment(0)
A
11

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.

Achromic answered 22/1, 2014 at 16:50 Comment(5)
actual both methods moved to GraphDatabaseService.(biDirectional)TraversalDescription()Kerbela
as I mentioned that the whole Traversal class is deprectated. @MichaelHunger comment clearified to use GraphDatabaseService traversalDescription method, instead of Node.traversal() or Traversal.traverse().Frisbee
The koans are undergoing a bit of an update right now (I'll push a new version for Neo4j 2.0 soon). Some of the exercises use deprecated code (two at least) so you might choose to ignore them. Overall you'll still get some value from completing the other exercises.Strobel
@JimWebber Hey Jim. I wasn't complaining about your Koans Test (which I really appretiate). Just confused about original Neo docs. Anyway, nice to know that you're still updating it. Maybe you want to add my PullRequest from today also :)Frisbee
Thx for changing the content Rafael, I saw the deprecation sign yesterday as well when I tried it in Neo4J 2.0.0 but then my internet went down and could not change it. It is a real pain that Neo4J documentation is sometimes very confusing as certain ways of calling the API change pretty frequently. I remember it took me quite a while to figure it out for the 1.x versions.Achromic

© 2022 - 2024 — McMap. All rights reserved.