Skip to content

Commit

Permalink
adding create node and relationship index
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Feb 23, 2011
1 parent 0029ce5 commit b32f7e1
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 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.9)
neography (0.0.10)
httparty (~> 0.7.3)
json

Expand Down
2 changes: 2 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,12 @@ To Use:
@neo.remove_relationship_properties(rel1, ["since","met"]) # Remove multiple properties of a relationship

@neo.list_node_indexes # gives names and query templates for all defined indices
@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.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_relationshp_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.get_relationship_index(index, key, value) # queries the relationship index with the given key/value pair
Expand Down
12 changes: 10 additions & 2 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def initialize(options={})
end

init.merge!(options)
puts init.inspect

@protocol = init[:protocol]
@server = init[:server]
Expand All @@ -41,7 +40,6 @@ def initialize(options={})
@max_threads = init[:max_threads]
@authentication = Hash.new
@authentication = {"#{init[:authentication]}_auth".to_sym => {:username => init[:username], :password => init[:password]}} unless init[:authentication].empty?
puts "Authentication: #{@authentication.inspect}"
end

def configure(protocol, server, port, directory)
Expand Down Expand Up @@ -240,6 +238,11 @@ def list_node_indexes
get("/index/node")
end

def create_node_index(name, type = "exact", provider = "lucene")
options = { :body => ({:name => name, :config => {:type => type, :provider => provider}}).to_json, :headers => {'Content-Type' => 'application/json'} }
post("/index/node", options)
end

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)
Expand All @@ -264,6 +267,11 @@ def list_relationship_indexes
get("/index/relationship")
end

def create_relationship_index(name, type = "exact", provider = "lucene")
options = { :body => ({:name => name, :config => {:type => type, :provider => provider}}).to_json, :headers => {'Content-Type' => 'application/json'} }
post("/index/relationship", options)
end

def add_relationship_to_index(index, key, value, id)
options = { :body => (self.configuration + "/relationship/#{get_id(id)}").to_json, :headers => {'Content-Type' => 'application/json'} }
post("/index/relationship/#{index}/#{key}/#{value}", options)
Expand Down
40 changes: 40 additions & 0 deletions spec/integration/rest_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,46 @@
end
end

describe "create an index" do
it "can create a node index" do
name = generate_text(6)
new_index = @neo.create_node_index(name)
new_index.should_not be_nil
new_index["template"].should == "#{@neo.configuration}/index/node/#{name}/{key}/{value}"
new_index["provider"].should == "lucene"
new_index["type"].should == "exact"
end

it "can create a node index with options" do
name = generate_text(6)
new_index = @neo.create_node_index(name, "fulltext","lucene")
new_index.should_not be_nil
new_index["template"].should == "#{@neo.configuration}/index/node/#{name}/{key}/{value}"
new_index["provider"].should == "lucene"
new_index["type"].should == "fulltext"
end

it "can create a relationship index" do
name = generate_text(6)
new_index = @neo.create_relationship_index(name)
new_index.should_not be_nil
new_index["template"].should == "#{@neo.configuration}/index/relationship/#{name}/{key}/{value}"
new_index["provider"].should == "lucene"
new_index["type"].should == "exact"
end

it "can create a relationship index with options" do
name = generate_text(6)
new_index = @neo.create_relationship_index(name, "fulltext","lucene")
new_index.should_not be_nil
new_index["template"].should == "#{@neo.configuration}/index/relationship/#{name}/{key}/{value}"
new_index["provider"].should == "lucene"
new_index["type"].should == "fulltext"
end


end

describe "add to index" do
it "can add a node to an index" do
new_node = @neo.create_node
Expand Down

0 comments on commit b32f7e1

Please sign in to comment.