kr1zmo
kr1zmo

Reputation: 837

How could I write a traversal query in neo4j (gremlin/cypher either one)?

Perferbly gremlin, but either one will do;

I am storing nodes in a database that form tree like structures. example: /dir/inside_dir/alaskan-natives/story1

Nodes are attached with a relationship called HAS_CHILD_NODE (if it would be more efficient to add properties to each relationship to speed up the query or make it more logical please inform me of this). Each node can only have one parent association. In one query - removing all looping from my application its self - how do I traverse down each path only to obtain specified ones until we have reached our end result.

Well assume I've already spliced at the '/' and now we have an array of hierarchal items we can attach to a query.

var array = ['dir', 'inside_dir', 'alaskan-natives', 'story1'];

Remember this must be a dynamic query allowing any amount of items to be traversed down the tree and consist of an ability to interchange hierarchal names. Try and optimize it please.

Just a simple tree to help in understanding; it is not related to my situation. Please view this tree example

Upvotes: 0

Views: 812

Answers (1)

Peter Neubauer
Peter Neubauer

Reputation: 6331

Covered on the mailing list for Neo4j, https://groups.google.com/group/neo4j/

Upvotes: 1

Related Questions