neography-down 1.6.4
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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.project +12 -0
- data/.rspec +1 -0
- data/.travis.yml +4 -0
- data/CHANGELOG.md +939 -0
- data/CONTRIBUTORS +18 -0
- data/Gemfile +4 -0
- data/Guardfile +14 -0
- data/LICENSE +19 -0
- data/README.md +281 -0
- data/Rakefile +14 -0
- data/examples/facebook.rb +40 -0
- data/examples/facebook_v2.rb +25 -0
- data/examples/greatest.rb +43 -0
- data/examples/linkedin.rb +39 -0
- data/examples/linkedin_v2.rb +22 -0
- data/examples/traversal_example1.rb +65 -0
- data/examples/traversal_example2.rb +54 -0
- data/lib/neography.rb +45 -0
- data/lib/neography/config.rb +64 -0
- data/lib/neography/connection.rb +263 -0
- data/lib/neography/equal.rb +21 -0
- data/lib/neography/errors.rb +60 -0
- data/lib/neography/index.rb +52 -0
- data/lib/neography/multi_json_parser.rb +28 -0
- data/lib/neography/neography.rb +10 -0
- data/lib/neography/node.rb +63 -0
- data/lib/neography/node_path.rb +29 -0
- data/lib/neography/node_relationship.rb +37 -0
- data/lib/neography/node_traverser.rb +146 -0
- data/lib/neography/path_traverser.rb +100 -0
- data/lib/neography/property.rb +110 -0
- data/lib/neography/property_container.rb +28 -0
- data/lib/neography/railtie.rb +19 -0
- data/lib/neography/relationship.rb +78 -0
- data/lib/neography/relationship_traverser.rb +80 -0
- data/lib/neography/rest.rb +99 -0
- data/lib/neography/rest/batch.rb +414 -0
- data/lib/neography/rest/clean.rb +17 -0
- data/lib/neography/rest/constraints.rb +38 -0
- data/lib/neography/rest/cypher.rb +29 -0
- data/lib/neography/rest/extensions.rb +21 -0
- data/lib/neography/rest/gremlin.rb +20 -0
- data/lib/neography/rest/helpers.rb +96 -0
- data/lib/neography/rest/node_auto_indexes.rb +60 -0
- data/lib/neography/rest/node_indexes.rb +139 -0
- data/lib/neography/rest/node_labels.rb +49 -0
- data/lib/neography/rest/node_paths.rb +49 -0
- data/lib/neography/rest/node_properties.rb +52 -0
- data/lib/neography/rest/node_relationships.rb +33 -0
- data/lib/neography/rest/node_traversal.rb +25 -0
- data/lib/neography/rest/nodes.rb +94 -0
- data/lib/neography/rest/other_node_relationships.rb +38 -0
- data/lib/neography/rest/relationship_auto_indexes.rb +60 -0
- data/lib/neography/rest/relationship_indexes.rb +142 -0
- data/lib/neography/rest/relationship_properties.rb +52 -0
- data/lib/neography/rest/relationship_types.rb +11 -0
- data/lib/neography/rest/relationships.rb +16 -0
- data/lib/neography/rest/schema_indexes.rb +26 -0
- data/lib/neography/rest/spatial.rb +137 -0
- data/lib/neography/rest/transactions.rb +101 -0
- data/lib/neography/tasks.rb +207 -0
- data/lib/neography/version.rb +3 -0
- data/neography.gemspec +39 -0
- data/spec/integration/authorization_spec.rb +40 -0
- data/spec/integration/broken_spatial_spec.rb +28 -0
- data/spec/integration/index_spec.rb +71 -0
- data/spec/integration/neography_spec.rb +10 -0
- data/spec/integration/node_encoding_spec.rb +71 -0
- data/spec/integration/node_path_spec.rb +222 -0
- data/spec/integration/node_relationship_spec.rb +381 -0
- data/spec/integration/node_spec.rb +260 -0
- data/spec/integration/parsing_spec.rb +13 -0
- data/spec/integration/performance_spec.rb +17 -0
- data/spec/integration/relationship_spec.rb +37 -0
- data/spec/integration/rest_batch_no_streaming_spec.rb +41 -0
- data/spec/integration/rest_batch_spec.rb +604 -0
- data/spec/integration/rest_batch_streaming_spec.rb +51 -0
- data/spec/integration/rest_bulk_spec.rb +106 -0
- data/spec/integration/rest_constraints_spec.rb +72 -0
- data/spec/integration/rest_experimental_spec.rb +22 -0
- data/spec/integration/rest_gremlin_fail_spec.rb +46 -0
- data/spec/integration/rest_header_spec.rb +15 -0
- data/spec/integration/rest_index_spec.rb +481 -0
- data/spec/integration/rest_labels_spec.rb +128 -0
- data/spec/integration/rest_node_spec.rb +274 -0
- data/spec/integration/rest_other_node_relationship_spec.rb +137 -0
- data/spec/integration/rest_path_spec.rb +231 -0
- data/spec/integration/rest_plugin_spec.rb +177 -0
- data/spec/integration/rest_relationship_spec.rb +354 -0
- data/spec/integration/rest_relationship_types_spec.rb +18 -0
- data/spec/integration/rest_schema_index_spec.rb +32 -0
- data/spec/integration/rest_spatial_spec.rb +166 -0
- data/spec/integration/rest_transaction_spec.rb +166 -0
- data/spec/integration/rest_traverse_spec.rb +149 -0
- data/spec/integration/unmanaged_spec.rb +27 -0
- data/spec/matchers.rb +33 -0
- data/spec/neography_spec.rb +23 -0
- data/spec/spec_helper.rb +44 -0
- data/spec/unit/config_spec.rb +135 -0
- data/spec/unit/connection_spec.rb +284 -0
- data/spec/unit/node_spec.rb +100 -0
- data/spec/unit/properties_spec.rb +285 -0
- data/spec/unit/relationship_spec.rb +118 -0
- data/spec/unit/rest/batch_spec.rb +262 -0
- data/spec/unit/rest/clean_spec.rb +16 -0
- data/spec/unit/rest/constraints_spec.rb +45 -0
- data/spec/unit/rest/cypher_spec.rb +20 -0
- data/spec/unit/rest/extensions_spec.rb +28 -0
- data/spec/unit/rest/gremlin_spec.rb +25 -0
- data/spec/unit/rest/helpers_spec.rb +124 -0
- data/spec/unit/rest/labels_spec.rb +77 -0
- data/spec/unit/rest/node_auto_indexes_spec.rb +70 -0
- data/spec/unit/rest/node_indexes_spec.rb +140 -0
- data/spec/unit/rest/node_paths_spec.rb +77 -0
- data/spec/unit/rest/node_properties_spec.rb +79 -0
- data/spec/unit/rest/node_relationships_spec.rb +57 -0
- data/spec/unit/rest/node_traversal_spec.rb +35 -0
- data/spec/unit/rest/nodes_spec.rb +187 -0
- data/spec/unit/rest/relationship_auto_indexes_spec.rb +66 -0
- data/spec/unit/rest/relationship_indexes_spec.rb +132 -0
- data/spec/unit/rest/relationship_properties_spec.rb +79 -0
- data/spec/unit/rest/relationship_types_spec.rb +15 -0
- data/spec/unit/rest/relationships_spec.rb +21 -0
- data/spec/unit/rest/schema_index_spec.rb +30 -0
- data/spec/unit/rest/transactions_spec.rb +43 -0
- metadata +372 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
module Neography
|
|
2
|
+
class Rest
|
|
3
|
+
module NodeProperties
|
|
4
|
+
|
|
5
|
+
def set_node_properties(id, properties)
|
|
6
|
+
properties.each do |property, value|
|
|
7
|
+
options = { :body => value.to_json, :headers => json_content_type }
|
|
8
|
+
@connection.put("/node/%{id}/properties/%{property}" % {:id => get_id(id), :property => property}, options)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def reset_node_properties(id, properties)
|
|
13
|
+
options = { :body => properties.to_json, :headers => json_content_type }
|
|
14
|
+
@connection.put("/node/%{id}/properties" % {:id => get_id(id)}, options)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def get_node_properties(id, *properties)
|
|
18
|
+
if properties.none?
|
|
19
|
+
@connection.get("/node/%{id}/properties" % {:id => get_id(id)})
|
|
20
|
+
else
|
|
21
|
+
get_each_node_properties(id, *properties)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def get_each_node_properties(id, *properties)
|
|
26
|
+
retrieved_properties = properties.flatten.inject({}) do |memo, property|
|
|
27
|
+
value = @connection.get("/node/%{id}/properties/%{property}" % {:id => get_id(id), :property => property})
|
|
28
|
+
memo[property] = value unless value.nil?
|
|
29
|
+
memo
|
|
30
|
+
end
|
|
31
|
+
return nil if retrieved_properties.empty?
|
|
32
|
+
retrieved_properties
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def remove_node_properties(id, *properties)
|
|
36
|
+
if properties.none?
|
|
37
|
+
@connection.delete("/node/%{id}/properties" % {:id => get_id(id)})
|
|
38
|
+
else
|
|
39
|
+
remove_each_node_properties(id, *properties)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def remove_each_node_properties(id, *properties)
|
|
44
|
+
properties.flatten.each do |property|
|
|
45
|
+
@connection.delete("/node/%{id}/properties/%{property}" % {:id => get_id(id), :property => property})
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module Neography
|
|
2
|
+
class Rest
|
|
3
|
+
module NodeRelationships
|
|
4
|
+
include Neography::Rest::Helpers
|
|
5
|
+
|
|
6
|
+
def create_relationship(type, from, to, properties = nil)
|
|
7
|
+
options = {
|
|
8
|
+
:body => {
|
|
9
|
+
:to => @connection.configuration + "/node/#{get_id(to)}",
|
|
10
|
+
:data => properties,
|
|
11
|
+
:type => type
|
|
12
|
+
}.to_json,
|
|
13
|
+
:headers => json_content_type }
|
|
14
|
+
|
|
15
|
+
@connection.post("/node/%{id}/relationships" % {:id => get_id(from)}, options)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def get_node_relationships(id, direction = nil, types = nil)
|
|
19
|
+
direction = parse_direction(direction)
|
|
20
|
+
|
|
21
|
+
if types.nil?
|
|
22
|
+
node_relationships = @connection.get("/node/%{id}/relationships/%{direction}" % {:id => get_id(id), :direction => direction}) || []
|
|
23
|
+
else
|
|
24
|
+
node_relationships = @connection.get("/node/%{id}/relationships/%{direction}/%{types}" % {:id => get_id(id), :direction => direction, :types => encode(Array(types).join('&'))}) || []
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
return [] if node_relationships.empty?
|
|
28
|
+
node_relationships
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Neography
|
|
2
|
+
class Rest
|
|
3
|
+
module NodeTraversal
|
|
4
|
+
include Neography::Rest::Helpers
|
|
5
|
+
|
|
6
|
+
def traverse(id, return_type, description)
|
|
7
|
+
options = { :body => {
|
|
8
|
+
"order" => parse_order(description["order"]),
|
|
9
|
+
"uniqueness" => parse_uniqueness(description["uniqueness"]),
|
|
10
|
+
"relationships" => description["relationships"],
|
|
11
|
+
"prune_evaluator" => description["prune evaluator"],
|
|
12
|
+
"return_filter" => description["return filter"],
|
|
13
|
+
"max_depth" => parse_depth(description["depth"])
|
|
14
|
+
}.to_json,
|
|
15
|
+
:headers => json_content_type
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type = parse_type(return_type)
|
|
19
|
+
|
|
20
|
+
@connection.post("/node/%{id}/traverse/%{type}" % {:id => get_id(id), :type => type}, options) || []
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
module Neography
|
|
2
|
+
class Rest
|
|
3
|
+
module Nodes
|
|
4
|
+
include Neography::Rest::Helpers
|
|
5
|
+
|
|
6
|
+
def get_node(id)
|
|
7
|
+
@connection.get("/node/%{id}" % {:id => get_id(id)})
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def get_nodes(*nodes)
|
|
11
|
+
gotten_nodes = []
|
|
12
|
+
Array(nodes).flatten.each do |node|
|
|
13
|
+
gotten_nodes << get_node(node)
|
|
14
|
+
end
|
|
15
|
+
gotten_nodes
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def get_root
|
|
19
|
+
root_node = @connection.get('/')["reference_node"]
|
|
20
|
+
@connection.get("/node/%{id}" % {:id => get_id(root_node)})
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def create_node(*args)
|
|
24
|
+
if args[0].respond_to?(:each_pair) && args[0]
|
|
25
|
+
create_node_with_attributes(args[0])
|
|
26
|
+
else
|
|
27
|
+
create_empty_node
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def create_node_with_attributes(attributes)
|
|
32
|
+
options = {
|
|
33
|
+
:body => attributes.delete_if { |k, v| v.nil? }.to_json,
|
|
34
|
+
:headers => json_content_type
|
|
35
|
+
}
|
|
36
|
+
@connection.post("/node", options)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def create_empty_node
|
|
40
|
+
@connection.post("/node")
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def delete_node(id)
|
|
44
|
+
@connection.delete("/node/%{id}" % {:id => get_id(id)})
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def create_nodes(nodes)
|
|
48
|
+
nodes = Array.new(nodes) if nodes.kind_of? Fixnum
|
|
49
|
+
created_nodes = []
|
|
50
|
+
nodes.each do |node|
|
|
51
|
+
created_nodes << create_node(node)
|
|
52
|
+
end
|
|
53
|
+
created_nodes
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def create_nodes_threaded(nodes)
|
|
57
|
+
nodes = Array.new(nodes) if nodes.kind_of? Fixnum
|
|
58
|
+
|
|
59
|
+
node_queue = Queue.new
|
|
60
|
+
thread_pool = []
|
|
61
|
+
responses = Queue.new
|
|
62
|
+
|
|
63
|
+
nodes.each do |node|
|
|
64
|
+
node_queue.push node
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
[nodes.size, @connection.max_threads].min.times do
|
|
68
|
+
thread_pool << Thread.new do
|
|
69
|
+
until node_queue.empty? do
|
|
70
|
+
node = node_queue.pop
|
|
71
|
+
if node.respond_to?(:each_pair)
|
|
72
|
+
responses.push( @connection.post("/node", {
|
|
73
|
+
:body => node.to_json,
|
|
74
|
+
:headers => json_content_type
|
|
75
|
+
} ) )
|
|
76
|
+
else
|
|
77
|
+
responses.push( @connection.post("/node") )
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
self.join
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
created_nodes = []
|
|
85
|
+
|
|
86
|
+
while created_nodes.size < nodes.size
|
|
87
|
+
created_nodes << responses.pop
|
|
88
|
+
end
|
|
89
|
+
created_nodes
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module Neography
|
|
2
|
+
class Rest
|
|
3
|
+
module OtherNodeRelationships
|
|
4
|
+
include Neography::Rest::Helpers
|
|
5
|
+
|
|
6
|
+
def get_node_relationships_to(id, other_id, direction = "all", types = [nil] )
|
|
7
|
+
|
|
8
|
+
body = case parse_direction(direction)
|
|
9
|
+
when "all"
|
|
10
|
+
"position.endNode().getId() == " + get_id(other_id)
|
|
11
|
+
when "in"
|
|
12
|
+
"position.length() > 0 && position.lastRelationship().getStartNode().getId() == " + get_id(other_id)
|
|
13
|
+
when "out"
|
|
14
|
+
"position.length() > 0 && position.lastRelationship().getEndNode().getId() == " + get_id(other_id)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
relationships = {:relationships => Array(types).map{|row| Hash[{:type => row}].merge({:direction => parse_direction(direction)})} }
|
|
18
|
+
|
|
19
|
+
if Array(types).first.nil?
|
|
20
|
+
relationships = {}
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
options = {
|
|
24
|
+
:body => {:order => "breadth_first",
|
|
25
|
+
:uniqueness => "relationship_global",
|
|
26
|
+
:max_depth => 1,
|
|
27
|
+
:return_filter => {:language => "javascript",
|
|
28
|
+
:body => body }
|
|
29
|
+
}.merge(relationships).to_json,
|
|
30
|
+
:headers => json_content_type
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@connection.post("/node/%{id}/traverse/relationship" % {:id => get_id(id)}, options) || []
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
module Neography
|
|
2
|
+
class Rest
|
|
3
|
+
module RelationshipAutoIndexes
|
|
4
|
+
|
|
5
|
+
def get_relationship_auto_index(key, value)
|
|
6
|
+
index = @connection.get("/index/auto/relationship/%{key}/%{value}" % {:key => key, :value => encode(value)}) || []
|
|
7
|
+
return nil if index.empty?
|
|
8
|
+
index
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def find_relationship_auto_index(key_or_query, value = nil)
|
|
12
|
+
if value
|
|
13
|
+
index = find_relationship_auto_index_by_value(key_or_query, value)
|
|
14
|
+
else
|
|
15
|
+
index = query_relationship_auto_index(key_or_query)
|
|
16
|
+
end
|
|
17
|
+
return nil if index.empty?
|
|
18
|
+
index
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def find_relationship_auto_index_by_value(key, value)
|
|
22
|
+
@connection.get("/index/auto/relationship/%{key}/%{value}" % {:key => key, :value => encode(value)}) || []
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def query_relationship_auto_index(query_expression)
|
|
26
|
+
@connection.get("/index/auto/relationship/?query=%{query}" % {:query => query_expression}) || []
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def get_relationship_auto_index_status
|
|
30
|
+
@connection.get("/index/auto/relationship/status")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def set_relationship_auto_index_status(value = true)
|
|
34
|
+
options = {
|
|
35
|
+
:body => value.to_json,
|
|
36
|
+
:headers => json_content_type
|
|
37
|
+
}
|
|
38
|
+
@connection.put("/index/auto/relationship/status", options)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def get_relationship_auto_index_properties
|
|
42
|
+
@connection.get("/index/auto/relationship/properties")
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def add_relationship_auto_index_property(property)
|
|
46
|
+
options = {
|
|
47
|
+
:body => property,
|
|
48
|
+
:headers => json_content_type
|
|
49
|
+
}
|
|
50
|
+
@connection.post("/index/auto/relationship/properties", options)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def remove_relationship_auto_index_property(property)
|
|
54
|
+
@connection.delete("/index/auto/relationship/properties/%{property}" % {:property => property})
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
module Neography
|
|
2
|
+
class Rest
|
|
3
|
+
module RelationshipIndexes
|
|
4
|
+
include Neography::Rest::Helpers
|
|
5
|
+
|
|
6
|
+
def list_relationship_indexes
|
|
7
|
+
@connection.get("/index/relationship")
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def create_relationship_index(name, type = "exact", provider = "lucene", extra_config = nil)
|
|
11
|
+
config = {
|
|
12
|
+
:type => type,
|
|
13
|
+
:provider => provider
|
|
14
|
+
}
|
|
15
|
+
config.merge!(extra_config) unless extra_config.nil?
|
|
16
|
+
options = {
|
|
17
|
+
:body => (
|
|
18
|
+
{ :name => name,
|
|
19
|
+
:config => config
|
|
20
|
+
}
|
|
21
|
+
).to_json,
|
|
22
|
+
:headers => json_content_type
|
|
23
|
+
}
|
|
24
|
+
@connection.post("/index/relationship", options)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def create_relationship_auto_index(type = "exact", provider = "lucene")
|
|
28
|
+
create_relationship_index("relationship_auto_index", type, provider)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def add_relationship_to_index(index, key, value, id, unique = false)
|
|
32
|
+
options = {
|
|
33
|
+
:body => (
|
|
34
|
+
{ :uri => @connection.configuration + "/relationship/#{get_id(id)}",
|
|
35
|
+
:key => key,
|
|
36
|
+
:value => value
|
|
37
|
+
}
|
|
38
|
+
).to_json,
|
|
39
|
+
:headers => json_content_type
|
|
40
|
+
}
|
|
41
|
+
path = unique ? "/index/relationship/%{index}?unique" % {:index => index} : "/index/relationship/%{index}" % {:index => index}
|
|
42
|
+
@connection.post(path, options)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def get_relationship_index(index, key, value)
|
|
46
|
+
index = @connection.get("/index/relationship/%{index}/%{key}/%{value}" % {:index => index, :key => key, :value => encode(value)}) || []
|
|
47
|
+
return nil if index.empty?
|
|
48
|
+
index
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def find_relationship_index(index, key_or_query, value = nil)
|
|
52
|
+
if value
|
|
53
|
+
index = find_relationship_index_by_key_value(index, key_or_query, value)
|
|
54
|
+
else
|
|
55
|
+
index = find_relationship_index_by_query(index, key_or_query)
|
|
56
|
+
end
|
|
57
|
+
return nil if index.empty?
|
|
58
|
+
index
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def find_relationship_index_by_key_value(index, key, value)
|
|
62
|
+
@connection.get("/index/relationship/%{index}/%{key}/%{value}" % {:index => index, :key => key, :value => encode(value)}) || []
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def find_relationship_index_by_query(index, query)
|
|
66
|
+
@connection.get("/index/relationship/%{index}?query=%{query}" % {:index => index, :query => encode(query)}) || []
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Mimick original neography API in Rest class.
|
|
70
|
+
def remove_relationship_from_index(index, id_or_key, id_or_value = nil, id = nil)
|
|
71
|
+
if id
|
|
72
|
+
remove_relationship_index_by_value(index, id, id_or_key, id_or_value)
|
|
73
|
+
elsif id_or_value
|
|
74
|
+
remove_relationship_index_by_key(index, id_or_value, id_or_key)
|
|
75
|
+
else
|
|
76
|
+
remove_relationship_index_by_id(index, id_or_key)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def remove_relationship_index_by_id(index, id)
|
|
81
|
+
@connection.delete("/index/relationship/%{index}/%{id}" % {:index => index, :id => get_id(id)})
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def remove_relationship_index_by_key(index, id, key)
|
|
85
|
+
@connection.delete("/index/relationship/%{index}/%{key}/%{id}" % {:index => index, :id => get_id(id), :key => key})
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def remove_relationship_index_by_value(index, id, key, value)
|
|
89
|
+
@connection.delete("/index/relationship/%{index}/%{key}/%{value}/%{id}" % {:index => index, :id => get_id(id), :key => key, :value => encode(value)})
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def drop_relationship_index(index)
|
|
93
|
+
@connection.delete("/index/relationship/%{index}" % {:index => index})
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def create_unique_relationship(index, key, value, type, from, to, props = nil)
|
|
97
|
+
body = {
|
|
98
|
+
:key => key,
|
|
99
|
+
:value => value,
|
|
100
|
+
:type => type,
|
|
101
|
+
:start => @connection.configuration + "/node/#{get_id(from)}",
|
|
102
|
+
:end => @connection.configuration + "/node/#{get_id(to)}"
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
body[:properties] = props unless props.nil?
|
|
106
|
+
|
|
107
|
+
options = { :body => body.to_json, :headers => json_content_type }
|
|
108
|
+
|
|
109
|
+
@connection.post("/index/relationship/%{index}?unique" % {:index => index}, options)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def get_or_create_unique_relationship(index, key, value, properties = {})
|
|
113
|
+
options = {
|
|
114
|
+
:body => (
|
|
115
|
+
{ :properties => properties,
|
|
116
|
+
:key => key,
|
|
117
|
+
:value => value
|
|
118
|
+
}
|
|
119
|
+
).to_json,
|
|
120
|
+
:headers => json_content_type
|
|
121
|
+
}
|
|
122
|
+
@connection.post("/index/relationship/%{index}?uniqueness=%{function}" % {:index => index, :function => 'get_or_create'}, options)
|
|
123
|
+
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def create_or_fail_unique_relationship(index, key, value, properties = {})
|
|
127
|
+
options = {
|
|
128
|
+
:body => (
|
|
129
|
+
{ :properties => properties,
|
|
130
|
+
:key => key,
|
|
131
|
+
:value => value
|
|
132
|
+
}
|
|
133
|
+
).to_json,
|
|
134
|
+
:headers => json_content_type
|
|
135
|
+
}
|
|
136
|
+
@connection.post("/index/relationship/%{index}?uniqueness=%{function}" % {:index => index, :function => 'create_or_fail'}, options)
|
|
137
|
+
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|