neography 0.0.10 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +1 -1
- data/README.rdoc +2 -0
- data/examples/traversal_example2.rb +54 -0
- data/lib/neography/rest.rb +15 -5
- data/lib/neography/version.rb +1 -1
- data/spec/integration/rest_index_spec.rb +40 -0
- metadata +5 -4
data/Gemfile.lock
CHANGED
data/README.rdoc
CHANGED
@@ -96,10 +96,12 @@ To Use:
|
|
96
96
|
@neo.remove_relationship_properties(rel1, ["since","met"]) # Remove multiple properties of a relationship
|
97
97
|
|
98
98
|
@neo.list_node_indexes # gives names and query templates for all defined indices
|
99
|
+
@neo.create_node_index(name, type, provider) # creates an index, defaults are "exact" and "lucene"
|
99
100
|
@neo.add_node_to_index(index, key, value, node1) # adds a node to the index with the given key/value pair
|
100
101
|
@neo.remove_node_from_index(index, key, value, node1) # removes a node from the index with the given key/value pair
|
101
102
|
@neo.get_node_index(index, key, value) # queries the index with the given key/value pair
|
102
103
|
@neo.list_relationship_indexes # gives names and query templates for relationship indices
|
104
|
+
@neo.create_relationshp_index(name, "fulltext", provider) # creates a relationship index with "fulltext" option
|
103
105
|
@neo.add_relationship_to_index(index, key, value, rel1) # adds a relationship to the index with the given key/value pair
|
104
106
|
@neo.remove_relationship_from_index(index, key, value, rel1) # removes a relationship from the index with the given key/value pair
|
105
107
|
@neo.get_relationship_index(index, key, value) # queries the relationship index with the given key/value pair
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'neography'
|
3
|
+
|
4
|
+
@neo = Neography::Rest.new
|
5
|
+
|
6
|
+
def create_node(name, mysql_id)
|
7
|
+
@neo.create_node("name" => name, "mysql_id" => mysql_id)
|
8
|
+
end
|
9
|
+
|
10
|
+
def attended(student, school, degree, graduated)
|
11
|
+
@neo.create_relationship("attended", student, school, {"degree" => degree, "graduated" => graduated})
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def graduated_with_me(student)
|
16
|
+
student = student["self"].split('/').last
|
17
|
+
student_attended = @neo.get_node_relationships(student)[0]
|
18
|
+
graduated = student_attended["data"]["graduated"]
|
19
|
+
school = student_attended["end"].split('/').last
|
20
|
+
|
21
|
+
@neo.traverse(school,"nodes", {"order" => "breadth first",
|
22
|
+
"uniqueness" => "node global",
|
23
|
+
"relationships" => {"type"=> "attended", "direction" => "in"},
|
24
|
+
"return filter" => {
|
25
|
+
"language" => "javascript",
|
26
|
+
"body" => "position.length() == 1
|
27
|
+
&& position.endNode().getId() != #{student}
|
28
|
+
&& position.lastRelationship().getProperty(\"graduated\") == #{graduated};"}})
|
29
|
+
end
|
30
|
+
|
31
|
+
charlie = create_node("Charlie", 1)
|
32
|
+
max = create_node("Max", 2)
|
33
|
+
peter = create_node("Peter", 3)
|
34
|
+
carol = create_node("Carol", 3)
|
35
|
+
tom = create_node("Tom", 4)
|
36
|
+
jerry = create_node("Jerry", 5)
|
37
|
+
larry = create_node("Larry", 6)
|
38
|
+
|
39
|
+
yale = create_node("Yale", 7)
|
40
|
+
harvard = create_node("Harvard", 8)
|
41
|
+
rutgers = create_node("Rutgers", 9)
|
42
|
+
|
43
|
+
attended(charlie,yale,"engineering", 2010)
|
44
|
+
attended(max,yale,"mathematics", 2005)
|
45
|
+
attended(peter,yale,"biology", 2010)
|
46
|
+
attended(carol,yale,"engineering", 2010)
|
47
|
+
attended(tom,harvard,"biology", 2008)
|
48
|
+
attended(jerry,rutgers,"physics", 2007)
|
49
|
+
attended(larry,rutgers,"mathematics", 2010)
|
50
|
+
|
51
|
+
|
52
|
+
puts "Charlie graduated with #{graduated_with_me(charlie).map{|n| n["data"]["name"]}.join(', ')}"
|
53
|
+
|
54
|
+
# The node levels returned are Peter, Carol
|
data/lib/neography/rest.rb
CHANGED
@@ -29,7 +29,6 @@ module Neography
|
|
29
29
|
end
|
30
30
|
|
31
31
|
init.merge!(options)
|
32
|
-
puts init.inspect
|
33
32
|
|
34
33
|
@protocol = init[:protocol]
|
35
34
|
@server = init[:server]
|
@@ -41,7 +40,6 @@ module Neography
|
|
41
40
|
@max_threads = init[:max_threads]
|
42
41
|
@authentication = Hash.new
|
43
42
|
@authentication = {"#{init[:authentication]}_auth".to_sym => {:username => init[:username], :password => init[:password]}} unless init[:authentication].empty?
|
44
|
-
puts "Authentication: #{@authentication.inspect}"
|
45
43
|
end
|
46
44
|
|
47
45
|
def configure(protocol, server, port, directory)
|
@@ -240,6 +238,11 @@ module Neography
|
|
240
238
|
get("/index/node")
|
241
239
|
end
|
242
240
|
|
241
|
+
def create_node_index(name, type = "exact", provider = "lucene")
|
242
|
+
options = { :body => ({:name => name, :config => {:type => type, :provider => provider}}).to_json, :headers => {'Content-Type' => 'application/json'} }
|
243
|
+
post("/index/node", options)
|
244
|
+
end
|
245
|
+
|
243
246
|
def add_node_to_index(index, key, value, id)
|
244
247
|
options = { :body => (self.configuration + "/node/#{get_id(id)}").to_json, :headers => {'Content-Type' => 'application/json'} }
|
245
248
|
post("/index/node/#{index}/#{key}/#{value}", options)
|
@@ -264,6 +267,11 @@ module Neography
|
|
264
267
|
get("/index/relationship")
|
265
268
|
end
|
266
269
|
|
270
|
+
def create_relationship_index(name, type = "exact", provider = "lucene")
|
271
|
+
options = { :body => ({:name => name, :config => {:type => type, :provider => provider}}).to_json, :headers => {'Content-Type' => 'application/json'} }
|
272
|
+
post("/index/relationship", options)
|
273
|
+
end
|
274
|
+
|
267
275
|
def add_relationship_to_index(index, key, value, id)
|
268
276
|
options = { :body => (self.configuration + "/relationship/#{get_id(id)}").to_json, :headers => {'Content-Type' => 'application/json'} }
|
269
277
|
post("/index/relationship/#{index}/#{key}/#{value}", options)
|
@@ -388,12 +396,14 @@ module Neography
|
|
388
396
|
|
389
397
|
def get_type(type)
|
390
398
|
case type
|
391
|
-
when :node, "nodes", :nodes, "nodes"
|
392
|
-
"node"
|
393
399
|
when :relationship, "relationship", :relationships, "relationships"
|
394
400
|
"relationship"
|
395
|
-
|
401
|
+
when :path, "path", :paths, "paths"
|
396
402
|
"path"
|
403
|
+
when :fullpath, "fullpath", :fullpaths, "fullpaths"
|
404
|
+
"fullpath"
|
405
|
+
else
|
406
|
+
"node"
|
397
407
|
end
|
398
408
|
end
|
399
409
|
|
data/lib/neography/version.rb
CHANGED
@@ -25,6 +25,46 @@ describe Neography::Rest do
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
describe "create an index" do
|
29
|
+
it "can create a node index" do
|
30
|
+
name = generate_text(6)
|
31
|
+
new_index = @neo.create_node_index(name)
|
32
|
+
new_index.should_not be_nil
|
33
|
+
new_index["template"].should == "#{@neo.configuration}/index/node/#{name}/{key}/{value}"
|
34
|
+
new_index["provider"].should == "lucene"
|
35
|
+
new_index["type"].should == "exact"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "can create a node index with options" do
|
39
|
+
name = generate_text(6)
|
40
|
+
new_index = @neo.create_node_index(name, "fulltext","lucene")
|
41
|
+
new_index.should_not be_nil
|
42
|
+
new_index["template"].should == "#{@neo.configuration}/index/node/#{name}/{key}/{value}"
|
43
|
+
new_index["provider"].should == "lucene"
|
44
|
+
new_index["type"].should == "fulltext"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "can create a relationship index" do
|
48
|
+
name = generate_text(6)
|
49
|
+
new_index = @neo.create_relationship_index(name)
|
50
|
+
new_index.should_not be_nil
|
51
|
+
new_index["template"].should == "#{@neo.configuration}/index/relationship/#{name}/{key}/{value}"
|
52
|
+
new_index["provider"].should == "lucene"
|
53
|
+
new_index["type"].should == "exact"
|
54
|
+
end
|
55
|
+
|
56
|
+
it "can create a relationship index with options" do
|
57
|
+
name = generate_text(6)
|
58
|
+
new_index = @neo.create_relationship_index(name, "fulltext","lucene")
|
59
|
+
new_index.should_not be_nil
|
60
|
+
new_index["template"].should == "#{@neo.configuration}/index/relationship/#{name}/{key}/{value}"
|
61
|
+
new_index["provider"].should == "lucene"
|
62
|
+
new_index["type"].should == "fulltext"
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
end
|
67
|
+
|
28
68
|
describe "add to index" do
|
29
69
|
it "can add a node to an index" do
|
30
70
|
new_node = @neo.create_node
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neography
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 11
|
10
|
+
version: 0.0.11
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Max De Marzi
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-02-
|
18
|
+
date: 2011-02-23 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- examples/linkedin.rb
|
120
120
|
- examples/linkedin_v2.rb
|
121
121
|
- examples/traversal_example1.rb
|
122
|
+
- examples/traversal_example2.rb
|
122
123
|
- lib/neography.rb
|
123
124
|
- lib/neography/config.rb
|
124
125
|
- lib/neography/equal.rb
|