Permalink
Browse files

adding indexes

  • Loading branch information...
1 parent 2b93d8e commit 2bedc626e20dc2eec46b6685ba9ac5b41fa951b9 @maxdemarzi maxdemarzi committed Nov 18, 2010
Showing with 79 additions and 1 deletion.
  1. +6 −1 README.rdoc
  2. +19 −0 lib/neography/rest.rb
  3. +48 −0 spec/integration/rest_spec.rb
  4. +6 −0 spec/spec_helper.rb
View
@@ -61,6 +61,11 @@ A thin ruby wrapper Neography::Rest which tries to mirror the Neo4j Rest API and
Neography::Rest.remove_relationship_properties(id, "since") # Remove one property of a relationship
Neography::Rest.remove_relationship_properties(id, ["since","met"]) # Remove multiple properties of a relationship
+ Neography::Rest.list_indexes # doesn't really seam to do what the api says it does
+ Neography::Rest.add_to_index(key, value, id) # adds a node to an index with the given key/value pair
+ Neography::Rest.remove_from_index(key, value, id) # removes a node to an index with the given key/value pair
+ Neography::Rest.get_index(key, value) # gets an index with the given key/value pair
+
... and a work in progress more rubyish layer that's not quite ready for use yet.
Neography::Node.new # Create an empty node
@@ -72,8 +77,8 @@ A thin ruby wrapper Neography::Rest which tries to mirror the Neo4j Rest API and
Neography::Node.del(3) # Deletes a node without any relationships
Neography::Node.del!(3) # Deletes a node and all its relationships
-
=== License
+
* Neography - MIT, see the LICENSE file http://github.com/maxdemarzi/neography/tree/master/LICENSE.
* Lucene - Apache, see http://lucene.apache.org/java/docs/features.html
* Neo4j - Dual free software/commercial license, see http://neo4j.org/
View
@@ -133,6 +133,25 @@ def delete_node!(id)
rescue_ij { delete("/node/#{id}") }
end
+ def list_indexes
+ rescue_ij { get("/index") }
+ end
+
+ def add_to_index(key, value, id)
+ options = { :body => (Neography::Config.to_s + "/node/#{id}").to_json, :headers => {'Content-Type' => 'application/json'} }
+ rescue_ij { post("/index/node/#{key}/#{value}", options) }
+ end
+
+ def remove_from_index(key, value, id)
+ rescue_ij { delete("/index/node/#{key}/#{value}/#{id}") }
+ end
+
+ def get_index(key, value)
+ index = rescue_ij { get("/index/node/#{key}/#{value}") } || Array.new
+ return nil if index.empty?
+ index
+ end
+
private
# Rescue from Invalid JSON error thrown by Crack Gem
@@ -599,4 +599,52 @@
end
end
+ describe "list indexes" do
+ it "can get a listing of indexes" do
+ Neography::Rest.list_indexes.should_not be_nil
+ end
+ end
+
+ describe "add to index" do
+ it "can add a node to an index" do
+ new_node = Neography::Rest.create_node
+ new_node[:id] = new_node["self"].split('/').last
+ key = generate_text(6)
+ value = generate_text
+ Neography::Rest.add_to_index(key, value, new_node[:id])
+ new_index = Neography::Rest.get_index(key, value)
+ new_index.should_not be_nil
+ Neography::Rest.remove_from_index(key, value, new_node[:id])
+ end
+ end
+
+ describe "remove from index" do
+ it "can remove a node from an index" do
+ new_node = Neography::Rest.create_node
+ new_node[:id] = new_node["self"].split('/').last
+ key = generate_text(6)
+ value = generate_text
+ Neography::Rest.add_to_index(key, value, new_node[:id])
+ new_index = Neography::Rest.get_index(key, value)
+ new_index.should_not be_nil
+ Neography::Rest.remove_from_index(key, value, new_node[:id])
+ new_index = Neography::Rest.get_index(key, value)
+ new_index.should be_nil
+ end
+ end
+
+ describe "get index" do
+ it "can get an index" do
+ new_node = Neography::Rest.create_node
+ new_node[:id] = new_node["self"].split('/').last
+ key = generate_text(6)
+ value = generate_text
+ Neography::Rest.add_to_index(key, value, new_node[:id])
+ new_index = Neography::Rest.get_index(key, value)
+ new_index.should_not be_nil
+ Neography::Rest.remove_from_index(key, value, new_node[:id])
+ end
+ end
+
+
end
View
@@ -11,3 +11,9 @@
FakeWeb.clean_registry
FakeWeb.allow_net_connect = true
+def generate_text(length=8)
+ chars = 'abcdefghjkmnpqrstuvwxyz'
+ key = ''
+ length.times { |i| key << chars[rand(chars.length)] }
+ key
+end

0 comments on commit 2bedc62

Please sign in to comment.