Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neo4j which Traversal should one use?

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?

like image 517
Rafael T Avatar asked Jan 22 '14 16:01

Rafael T


People also ask

What is traversal Neo4j?

The Neo4j Traversal framework Java API is a callback-based, lazily-executed way of specifying desired movements through a graph in Java. Some traversal examples are collected under Traversal. You can also use the Cypher query language as a powerful declarative way to query the graph.

What can you do to improve the performance of Neo4j?

The size of the available heap memory is an important aspect for the performance of Neo4j. Generally speaking, it is beneficial to configure a large enough heap space to sustain concurrent operations. For many setups, a heap size between 8G and 16G is large enough to run Neo4j reliably.

What are the weaknesses of Neo4j?

Neo4j has some upper bound limit for the graph size and can support tens of billions of nodes, properties, and relationships in a single graph. No security is provided at the data level and there is no data encryption. Security auditing is not available in Neo4j.


1 Answers

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.

like image 114
ddem Avatar answered Sep 21 '22 15:09

ddem