Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 40 lines (32 sloc) 1.341 kB
34068ab @maxdemarzi adding examples and get_relationship
authored
1 require 'rubygems'
2 require 'neography'
3
b48276d @maxdemarzi it's ruby, not java, skip the parenthesis
authored
4 @neo = Neography::Rest.new
34068ab @maxdemarzi adding examples and get_relationship
authored
5
6 def create_person(name)
7 @neo.create_node("name" => name)
8 end
9
10 def make_mutual_friends(node1, node2)
11 @neo.create_relationship("friends", node1, node2)
12 @neo.create_relationship("friends", node2, node1)
13 end
14
15 def suggestions_for(node)
9dce8b7 @maxdemarzi easier way to do friend suggestions
authored
16 @neo.traverse(node,"nodes", {"order" => "breadth first",
17 "uniqueness" => "node global",
18 "relationships" => {"type"=> "friends", "direction" => "in"},
19 "return filter" => {
20 "language" => "javascript",
21 "body" => "position.length() == 2;"},
22 "depth" => 2})
34068ab @maxdemarzi adding examples and get_relationship
authored
23 end
24
25 johnathan = create_person('Johnathan')
26 mark = create_person('Mark')
27 phill = create_person('Phill')
28 mary = create_person('Mary')
29 luke = create_person('Luke')
30
31 make_mutual_friends(johnathan, mark)
32 make_mutual_friends(mark, mary)
33 make_mutual_friends(mark, phill)
34 make_mutual_friends(phill, mary)
35 make_mutual_friends(phill, luke)
36
37 puts "Johnathan should become friends with #{suggestions_for(johnathan).map{|n| n["data"]["name"]}.join(', ')}"
38
39 # RESULT
40 # Johnathan should become friends with Mary, Phill
Something went wrong with that request. Please try again.