Skip to content

Commit

Permalink
adding new ways to remove nodes and relationships from an index
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Mar 11, 2011
1 parent 1ede7a9 commit 3e41e09
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 5 deletions.
6 changes: 5 additions & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ in order to access the functionality.

=== Try it now!

I am hosting an instance of Neo4j (1.2) at neography.org for you to try out.
I am hosting an instance of Neo4j (1.3M04) at neography.org for you to try out.

You can see the administration at: {Neo4j Web Admin}[http://neography.org]

Expand Down Expand Up @@ -99,11 +99,15 @@ To Use:
@neo.create_node_index(name, type, provider) # creates an index, defaults are "exact" and "lucene"
@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.remove_node_from_index(index, key, node1) # removes a node from the index with the given key
@neo.remove_node_from_index(index, node1) # removes a node from the index
@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.create_relationship_index(name, "fulltext", provider) # creates a relationship index with "fulltext" option
@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.remove_relationship_from_index(index, key, rel1) # removes a relationship from the index with the given key
@neo.remove_relationship_from_index(index, rel1) # removes a relationship from the index
@neo.get_relationship_index(index, key, value) # queries the relationship index with the given key/value pair


Expand Down
16 changes: 12 additions & 4 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,12 @@ def add_node_to_index(index, key, value, id)
post("/index/node/#{index}/#{key}/#{value}", options)
end

def remove_node_from_index(index, key, value, id)
delete("/index/node/#{index}/#{key}/#{value}/#{get_id(id)}")
def remove_node_from_index(*args)
case args.size
when 4 then delete("/index/node/#{args[0]}/#{args[1]}/#{args[2]}/#{get_id(args[3])}")
when 3 then delete("/index/node/#{args[0]}/#{args[1]}/#{get_id(args[2])}")
when 2 then delete("/index/node/#{args[0]}/#{get_id(args[1])}")
end
end

def get_node_index(index, key, value)
Expand Down Expand Up @@ -277,8 +281,12 @@ def add_relationship_to_index(index, key, value, id)
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)}")
def remove_relationship_from_index(*args)
case args.size
when 4 then delete("/index/relationship/#{args[0]}/#{args[1]}/#{args[2]}/#{get_id(args[3])}")
when 3 then delete("/index/relationship/#{args[0]}/#{args[1]}/#{get_id(args[2])}")
when 2 then delete("/index/relationship/#{args[0]}/#{get_id(args[1])}")
end
end

def get_relationship_index(index, key, value)
Expand Down
52 changes: 52 additions & 0 deletions spec/integration/rest_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,30 @@
new_index.should be_nil
end

it "can remove a node from an index without supplying value" do
new_node = @neo.create_node
key = generate_text(6)
value = generate_text
@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, new_node)
new_index = @neo.get_node_index("test_index", key, value)
new_index.should be_nil
end

it "can remove a node from an index without supplying key nor value" do
new_node = @neo.create_node
key = generate_text(6)
value = generate_text
@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", 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
Expand All @@ -115,6 +139,34 @@
new_index = @neo.get_relationship_index("test_index", key, value)
new_index.should be_nil
end

it "can remove a relationshp from an index without supplying value" 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, new_relationship)
new_index = @neo.get_relationship_index("test_index", key, value)
new_index.should be_nil
end

it "can remove a relationshp from an index without supplying key nor value" 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", new_relationship)
new_index = @neo.get_relationship_index("test_index", key, value)
new_index.should be_nil
end
end

describe "get index" do
Expand Down

0 comments on commit 3e41e09

Please sign in to comment.