diff --git a/Gemfile.lock b/Gemfile.lock index 26600af..edf7628 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - neography (0.0.9) + neography (0.0.10) httparty (~> 0.7.3) json diff --git a/README.rdoc b/README.rdoc index ee54a53..bb55c38 100644 --- a/README.rdoc +++ b/README.rdoc @@ -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 diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index 81e62a9..9048913 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -29,7 +29,6 @@ def initialize(options={}) end init.merge!(options) - puts init.inspect @protocol = init[:protocol] @server = init[:server] @@ -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) @@ -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) @@ -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) diff --git a/spec/integration/rest_index_spec.rb b/spec/integration/rest_index_spec.rb index 20fd9bc..4ba24c6 100644 --- a/spec/integration/rest_index_spec.rb +++ b/spec/integration/rest_index_spec.rb @@ -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