0

I have 2 questions

1.If I have a graph like below

A->B->C->D

A->B->C->E

My requirement is to get the path (start to the very end) so I can traverse the nodes and perform some actions based on the criteria.

I'm using Traversal Description with uniqueness option as below. TraversalDescription td = Traversal.description() .relationships(KNOWS, Direction.OUTGOING) .uniqueness(Uniqueness.NODE_PATH) .evaluator(Evaluators.excludeStartPosition());

I'm expecting the below results

A->B->C->D

A->B->C->E

But I'm getting the below results. I tried both NODE_PATH and NODE_GLOBAL.

A->B

A->B->C

A->B->C->D

A->B->C->E

2.What is the most efficient way to clean up the old nodes which are no longer needed (based on time stamp)? I have 2 options 1.Traverse the node from start to end and collect the node ids that can be deleted. Then loop through the list and delete the node and it's relationships/nodes 2. Cypher-query to delete node and relationship matching the date criteria

Thanks a lot in advance!

1 Answers1

1

Answering (1) uniqueness controls which nodes/relationships will be (re)visited during a traversal. However it doesn't control which paths gets returned out to the Path iterator. That behaviour you'll have to encode in an Evaluator. In your case it could be an evaluator based on path length or a particular criteria on the end node, e.g:

// for A->B->C->D Evaluators.atDepth( 3 )

or

// for returning paths where the end node has property "bla" new Evaluator() { public Evaluation evaluate( Path path ) { return Evaluation.ofIncludes( path.endNode().hasProperty( "bla" ) ); } }

Unfortunately there's no built-in way of getting only the longest paths it visits in each branch. It would be a nice feature actually.

Mattias Finné
  • 3,034
  • 1
  • 15
  • 7
  • To get longest paths in cypher see this question: http://stackoverflow.com/questions/19764527/how-to-find-all-the-longest-paths-with-cypher-query – LameCoder May 07 '14 at 20:22
  • Thanks Mattias Persson for taking time to respond. Currently I'm traversing the node manually using it's relationships to avoid traversing the same node multiple times. Is there any other efficient way to traverse the nodes? – user3564731 May 07 '14 at 21:04