Skip to content

Commit

Permalink
do not send max depth in traversal if not specified during, added exa…
Browse files Browse the repository at this point in the history
…mple
  • Loading branch information
maxdemarzi committed Nov 22, 2010
1 parent b48276d commit 2a6a4bf
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
65 changes: 65 additions & 0 deletions examples/traversal_example1.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
require 'rubygems'
require 'neography'

@neo = Neography::Rest.new

def create_node(level, type)
@neo.create_node("NODE_LEVEL" => level, "TYPE" => type)
end

def create_other_node(type)
@neo.create_node("TYPE" => type)
end


def get_nodes_by_level(level, node)
starting_id = node["self"].split('/').last

@neo.traverse(node,"nodes", {"order" => "breadth first",
"uniqueness" => "node global",
"relationships" => {"type"=> "linked", "direction" => "out"},
"prune evaluator" => {
"language" => "javascript",
"body" => "position.startNode().hasProperty('NODE_LEVEL')
&& position.startNode().getProperty('NODE_LEVEL')==5
&& position.startNode().getId()!=#{starting_id};"},
"return filter" => {
"language" => "javascript",
"body" => "position.endNode().hasProperty('NODE_LEVEL') && position.endNode().getProperty('NODE_LEVEL')==5;"}})
end

node1 = create_node(5, "N")
node2 = create_node(5, "N")
node3 = create_node(5, "N")
node4 = create_node(5, "N")
node5 = create_node(5, "N")
node6 = create_node(5, "N")
node7 = create_node(5, "N")

node8 = create_other_node("Y")
node9 = create_other_node("Y")
node10 = create_other_node("Y")

node11 = create_node(6, "N")
node12 = create_node(7, "N")
node13 = create_node(8, "N")


@neo.create_relationship("linked", node1, node2)
@neo.create_relationship("linked", node2, node3)
@neo.create_relationship("linked", node3, node4)
@neo.create_relationship("linked", node4, node5)
@neo.create_relationship("linked", node5, node6)
@neo.create_relationship("linked", node6, node7)

@neo.create_relationship("linked", node2, node8)
@neo.create_relationship("linked", node3, node9)
@neo.create_relationship("linked", node4, node10)

@neo.create_relationship("linked", node5, node11)
@neo.create_relationship("linked", node6, node12)
@neo.create_relationship("linked", node7, node13)

puts "The node levels returned are #{get_nodes_by_level(5, node1).map{|n| n["data"]["NODE_LEVEL"]}.join(', ')}"

# The node levels returned are 5, 5, 5, 5, 5, 5, 5
1 change: 1 addition & 0 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ def get_uniqueness(uniqueness)
end

def get_depth(depth)
return nil if depth.nil?
return 1 if depth.to_i == 0
depth.to_i
end
Expand Down

0 comments on commit 2a6a4bf

Please sign in to comment.