Skip to content

Commit

Permalink
working on relationship indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Feb 6, 2011
1 parent 64fbdfd commit 2015a05
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
neography (0.0.7)
neography (0.0.9)
httparty (~> 0.7.3)
json

Expand Down
13 changes: 9 additions & 4 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,15 @@ To Use:
@neo.remove_relationship_properties(rel1, "since") # Remove one property of a relationship
@neo.remove_relationship_properties(rel1, ["since","met"]) # Remove multiple properties of a relationship

@neo.list_indexes # gives names and query templates for all defined indices
@neo.add_to_index(index, key, value, node1) # adds a node to the specified index with the given key/value pair
@neo.remove_from_index(index, key, value, node1) # removes a node from the specified index with the given key/value pair
@neo.get_index(index, key, value) # queries the specified index with the given key/value pair
@neo.list_node_indexes # gives names and query templates for all defined indices
@neo.add_node_to_index(index, key, value, node1) # adds a node to the index with the given key/value pair
@neo.remove_node_from_index(index, key, value, node1) # removes a node from the index with the given key/value pair
@neo.get_node_index(index, key, value) # queries the index with the given key/value pair
@neo.list_relationship_indexes # gives names and query templates for relationship indices
@neo.add_relationship_to_index(index, key, value, rel1) # adds a relationship to the index with the given key/value pair
@neo.remove_relationship_from_index(index, key, value, rel1) # removes a relationship from the index with the given key/value pair
@neo.get_relationship_index(index, key, value) # queries the relationship index with the given key/value pair


@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
Expand Down
31 changes: 27 additions & 4 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,25 +219,48 @@ def delete_node!(id)
delete("/node/#{get_id(id)}")
end

def list_indexes
def list_node_indexes
get("/index/node")
end

def add_to_index(index, key, value, id)
def add_node_to_index(index, key, value, id)
options = { :body => (self.configuration + "/node/#{get_id(id)}").to_json, :headers => {'Content-Type' => 'application/json'} }
post("/index/node/#{index}/#{key}/#{value}", options)
end

def remove_from_index(index, key, value, id)
def remove_node_from_index(index, key, value, id)
delete("/index/node/#{index}/#{key}/#{value}/#{get_id(id)}")
end

def get_index(index, key, value)
def get_node_index(index, key, value)
index = get("/index/node/#{index}/#{key}/#{value}") || Array.new
return nil if index.empty?
index
end

alias_method :list_indexes, :list_node_indexes
alias_method :add_to_index, :add_node_to_index
alias_method :remove_from_index, :remove_node_from_index
alias_method :get_index, :get_node_index

def list_relationship_indexes
get("/index/relationship")
end

def add_relationship_to_index(index, key, value, id)
options = { :body => (self.configuration + "/node/#{get_id(id)}").to_json, :headers => {'Content-Type' => 'application/json'} }
post("/index/relationship/#{index}/#{key}/#{value}", options)
end

def remove_relationship_from_index(index, key, value, id)
delete("/index/relationship/#{index}/#{key}/#{value}/#{get_id(id)}")
end

def get_relationship_index(index, key, value)
index = get("/index/relationship/#{index}/#{key}/#{value}") || Array.new
return nil if index.empty?
index
end
def traverse(id, return_type, description)
options = { :body => {"order" => get_order(description["order"]),
"uniqueness" => get_uniqueness(description["uniqueness"]),
Expand Down
File renamed without changes.
74 changes: 61 additions & 13 deletions spec/integration/rest_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,46 @@
end

describe "list indexes" do
it "can get a listing of indexes" do
it "can get a listing of node indexes" do
new_node = @neo.create_node
key = generate_text(6)
value = generate_text
@neo.add_to_index("test_index", key, value, new_node)
@neo.add_node_to_index("test_index", key, value, new_node)
@neo.list_indexes.should_not be_nil
end

it "can get a listing of relationship indexes" do
new_node1 = @neo.create_node
new_node2 = @neo.create_node
new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
key = generate_text(6)
value = generate_text
@neo.add_relationship_to_index("test_index", key, value, new_relationship)
@neo.list_relationship_indexes.should_not be_nil
end
end

describe "add to index" do
it "can add a node to an index" do
new_node = @neo.create_node
key = generate_text(6)
value = generate_text
@neo.add_to_index("test_index", key, value, new_node)
new_index = @neo.get_index("test_index", key, value)
@neo.add_node_to_index("test_index", key, value, new_node)
new_index = @neo.get_node_index("test_index", key, value)
new_index.should_not be_nil
@neo.remove_node_from_index("test_index", key, value, new_node)
end

it "can add a relationship to an index" do
new_node1 = @neo.create_node
new_node2 = @neo.create_node
new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
key = generate_text(6)
value = generate_text
@neo.add_relationship_to_index("test_index", key, value, new_relationship)
new_index = @neo.get_relationship_index("test_index", key, value)
new_index.should_not be_nil
@neo.remove_from_index("test_index", key, value, new_node)
@neo.remove_relationship_from_index("test_index", key, value, new_relationship)
end
end

Expand All @@ -32,24 +54,50 @@
new_node = @neo.create_node
key = generate_text(6)
value = generate_text
@neo.add_to_index("test_index", key, value, new_node)
new_index = @neo.get_index("test_index", key, value)
@neo.add_node_to_index("test_index", key, value, new_node)
new_index = @neo.get_node_index("test_index", key, value)
new_index.should_not be_nil
@neo.remove_from_index("test_index", key, value, new_node)
new_index = @neo.get_index("test_index", key, value)
@neo.remove_node_from_index("test_index", key, value, new_node)
new_index = @neo.get_node_index("test_index", key, value)
new_index.should be_nil
end

it "can remove a relationshp from an index" do
new_node1 = @neo.create_node
new_node2 = @neo.create_node
new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
key = generate_text(6)
value = generate_text
@neo.add_relationship_to_index("test_index", key, value, new_relationship)
new_index = @neo.get_relationship_index("test_index", key, value)
new_index.should_not be_nil
@neo.remove_relationship_from_index("test_index", key, value, new_relationship)
new_index = @neo.get_relationship_index("test_index", key, value)
new_index.should be_nil
end
end

describe "get index" do
it "can get an index" do
it "can get a node index" do
new_node = @neo.create_node
key = generate_text(6)
value = generate_text
@neo.add_to_index("test_index", key, value, new_node)
new_index = @neo.get_index("test_index", key, value)
@neo.add_node_to_index("test_index", key, value, new_node)
new_index = @neo.get_node_index("test_index", key, value)
new_index.should_not be_nil
@neo.remove_node_from_index("test_index", key, value, new_node)
end

it "can get a relationship index" do
new_node1 = @neo.create_node
new_node2 = @neo.create_node
new_relationship = @neo.create_relationship("friends", new_node1, new_node2)
key = generate_text(6)
value = generate_text
@neo.add_relationship_to_index("test_index", key, value, new_relationship)
new_index = @neo.get_relationship_index("test_index", key, value)
new_index.should_not be_nil
@neo.remove_from_index("test_index", key, value, new_node)
@neo.remove_relationship_from_index("test_index", key, value, new_relationship)
end
end

Expand Down

0 comments on commit 2015a05

Please sign in to comment.