-
Notifications
You must be signed in to change notification settings - Fork 135
Paths and traversal
ecoologic edited this page Oct 12, 2012
·
2 revisions
@neo.get_path(node1, node2, relationships, depth=4, algorithm="shortestPath") # finds the shortest path between two nodes
@neo.get_paths(node1, node2, relationships, depth=3, algorithm="allPaths") # finds all paths between two nodes
@neo.get_shortest_weighted_path(node1, node2, relationships, # find the shortest path between two nodes
weight_attr='weight', depth=2, # accounting for weight in the relationships
algorithm='dijkstra') # using 'weight' as the attribute
nodes = @neo.traverse(node1, # the node where the traversal starts
"nodes", # return_type "nodes", "relationships" or "paths"
{"order" => "breadth first", # "breadth first" or "depth first" traversal order
"uniqueness" => "node global", # See Uniqueness in API documentation for options.
"relationships" => [{"type"=> "roommates", # A hash containg a description of the traversal
"direction" => "all"}, # two relationships.
{"type"=> "friends", #
"direction" => "out"}], #
"prune evaluator" => {"language" => "javascript", # A prune evaluator (when to stop traversing)
"body" => "position.endNode().getProperty('age') < 21;"},
"return filter" => {"language" => "builtin", # "all" or "all but start node"
"name" => "all"},
"depth" => 4})
"depth" is a short-hand way of specifying a prune evaluator which prunes after a certain depth.
Traversal algorithms can be found in NodePath module, relationships
are of the format {"type" => relationship_name, "direction" => "in"}
where possible directions are in
, out
and all
.
If not specified a depth of 1 is used and if a "prune evaluator" is specified instead of a depth, no depth limit is set.