diff --git a/README.rdoc b/README.rdoc index af8e43d..4b79e74 100644 --- a/README.rdoc +++ b/README.rdoc @@ -144,6 +144,7 @@ To Use: @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.create_node_auto_index(type, provider) # creates an auto 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 @@ -155,6 +156,7 @@ To Use: @neo.find_node_auto_index(query) # advanced query of the node auto index with the given query @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.create_relationship_auto_index("fulltext", provider) # creates a relationship auto 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 @@ -164,6 +166,18 @@ To Use: @neo.find_relationship_index(index, query) # advanced query of the relationship index with the given query @neo.get_relationship_auto_index(key, value) # exact query of the relationship auto index with the given key/value pair @neo.find_relationship_auto_index(query) # advanced query of the relationship auto index with the given query + + @neo.get_node_auto_index_status # true or false depending on node auto index setting + @neo.get_relationship_auto_index_status # true or false depending on relationship auto index setting + @neo.set_node_auto_index_status(true) # set the node auto index setting to true + @neo.set_relationship_auto_index_status(false) # set the relationship auto index setting to false + @neo.get_node_auto_index_properties # array of currently auto indexed node properties + @neo.get_relationship_auto_index_properties # array of currently auto indexed relationship properties + @neo.add_node_auto_index_property(property) # add to auto indexed node properties + @neo.remove_node_auto_index_property(property) # remove from auto indexed node properties + @neo.add_relationship_auto_index_property(property) # add to auto indexed relationship properties + @neo.remove_relationship_auto_index_property(property) # remove from auto indexed relationship properties + @neo.execute_script("g.v(0)") # sends a Groovy script (through the Gremlin plugin) @neo.execute_script("g.v(id)", {:id => 3}) # sends a parameterized Groovy script (optimized for repeated calls) @neo.execute_query("start n=node(0) return n") # sends a Cypher query (through the Cypher plugin) diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index 9d3d113..c527b39 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -267,6 +267,10 @@ def create_node_index(name, type = "exact", provider = "lucene") post("/index/node", options) end + def create_node_auto_index(type = "exact", provider = "lucene") + create_node_index("node_auto_index", type, provider) + end + def add_node_to_index(index, key, value, id) options = { :body => ({:uri => self.configuration + "/node/#{get_id(id)}", :key => key, :value => value }).to_json, :headers => {'Content-Type' => 'application/json'} } post("/index/node/#{index}", options) @@ -297,8 +301,11 @@ def get_node_auto_index(key, value) index end - def find_node_auto_index(query) - index = get("/index/auto/node/?query=#{query}") || Array.new + def find_node_auto_index(*args) + case args.size + when 2 then index = get("/index/auto/node/#{args[0]}/#{args[1]}") || Array.new + when 1 then index = get("/index/auto/node/?query=#{args[0]}") || Array.new + end return nil if index.empty? index end @@ -326,6 +333,10 @@ def create_relationship_index(name, type = "exact", provider = "lucene") post("/index/relationship", options) end + def create_relationship_auto_index(type = "exact", provider = "lucene") + create_relationship_index("relationship_auto_index", type, provider) + end + def add_relationship_to_index(index, key, value, id) options = { :body => ({:uri => self.configuration + "/relationship/#{get_id(id)}", :key => key, :value => value}).to_json, :headers => {'Content-Type' => 'application/json'} } post("/index/relationship/#{index}", options) @@ -360,12 +371,59 @@ def get_relationship_auto_index(key, value) index end - def find_relationship_auto_index(query) - index = get("/index/auto/relationship/?query=#{query}") || Array.new + def find_relationship_auto_index(*args) + case args.size + when 2 then index = get("/index/auto/relationship/#{args[0]}/#{args[1]}") || Array.new + when 1 then index = get("/index/auto/relationship/?query=#{args[0]}") || Array.new + end return nil if index.empty? index end + def get_node_auto_index_status + get("/index/auto/node/status") + end + + def get_relationship_auto_index_status + get("/index/auto/relationship/status") + end + + def set_node_auto_index_status(change_to = true) + options = { :body => change_to.to_json, :headers => {'Content-Type' => 'application/json'} } + put("/index/auto/node/status", options) + end + + def set_relationship_auto_index_status(change_to = true) + options = { :body => change_to.to_json, :headers => {'Content-Type' => 'application/json'} } + put("/index/auto/relationship/status", options) + end + + def get_node_auto_index_properties + get("/index/auto/node/properties") + end + + def get_relationship_auto_index_properties + get("/index/auto/relationship/properties") + end + + def add_node_auto_index_property(property) + options = { :body => property, :headers => {'Content-Type' => 'application/json'} } + post("/index/auto/node/properties", options) + end + + def remove_node_auto_index_property(property) + delete("/index/auto/node/properties/#{property}") + end + + def add_relationship_auto_index_property(property) + options = { :body => property, :headers => {'Content-Type' => 'application/json'} } + post("/index/auto/relationship/properties", options) + end + + def remove_relationship_auto_index_property(property) + delete("/index/auto/relationship/properties/#{property}") + end + def traverse(id, return_type, description) options = { :body => {"order" => get_order(description["order"]), "uniqueness" => get_uniqueness(description["uniqueness"]), diff --git a/spec/integration/rest_index_spec.rb b/spec/integration/rest_index_spec.rb index 08720c9..19377ae 100644 --- a/spec/integration/rest_index_spec.rb +++ b/spec/integration/rest_index_spec.rb @@ -294,21 +294,95 @@ end describe "auto indexes" do + + it "can check the status of node auto index" do + @neo.get_node_auto_index_status.should satisfy{|status| [true, false].include?(status)} + end + it "can check the status of relationship auto index" do + @neo.get_relationship_auto_index_status.should satisfy{|status| [true, false].include?(status)} + end + + it "can change the node auto index status" do + @neo.set_node_auto_index_status(true) + @neo.get_node_auto_index_status.should be_true + end + + it "can change the relationship auto index status" do + @neo.set_relationship_auto_index_status(true) + @neo.get_relationship_auto_index_status.should be_true + end + + it "can get a list of auto indexed node properties" do + @neo.set_node_auto_index_status(true) + @neo.create_node_auto_index + @neo.add_node_auto_index_property("name") + @neo.get_node_auto_index_properties.should == ["name"] + end + + it "can get a list of auto indexed relationship properties" do + @neo.set_relationship_auto_index_status(true) + @neo.create_relationship_auto_index + @neo.add_relationship_auto_index_property("weight") + @neo.get_relationship_auto_index_properties.should == ["weight"] + end + + it "can remove a property from the auto indexed node properties" do + @neo.add_node_auto_index_property("name") + @neo.add_node_auto_index_property("label") + @neo.get_node_auto_index_properties.should == ["name", "label"] + @neo.remove_node_auto_index_property("label") + @neo.get_node_auto_index_properties.should == ["name"] + end + + it "can remove a property from the auto indexed relationship properties" do + @neo.add_relationship_auto_index_property("weight") + @neo.add_relationship_auto_index_property("strength") + @neo.get_relationship_auto_index_properties.should == ["weight", "strength"] + @neo.remove_relationship_auto_index_property("strength") + @neo.get_relationship_auto_index_properties.should == ["weight"] + end + it "can get a node from an automatic index" do - pending + new_node = @neo.create_node("name" => "Max") + existing_nodes = @neo.get_node_auto_index("name", "Max") + existing_nodes.collect{|n| n["self"]}.include?(new_node["self"]).should be_true + end + + it "can query a node from an automatic index using key value" do + new_node = @neo.create_node("name" => "Max") + existing_nodes = @neo.find_node_auto_index("name", "Max") + existing_nodes.collect{|n| n["self"]}.include?(new_node["self"]).should be_true end it "can query a node from an automatic index" do - pending + new_node = @neo.create_node("name" => "Max") + existing_nodes = @neo.find_node_auto_index("name:Max") + existing_nodes.collect{|n| n["self"]}.include?(new_node["self"]).should be_true end it "can get a relationship from an automatic index" do - pending + new_node1 = @neo.create_node("name" => "Max") + new_node2 = @neo.create_node("name" => "Peter") + new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"weight" => 5}) + existing_rels = @neo.get_relationship_auto_index("weight", 5) + existing_rels.collect{|n| n["self"]}.include?(new_relationship["self"]).should be_true + end + + it "can query a relationship from an automatic index using key value" do + new_node1 = @neo.create_node("name" => "Max") + new_node2 = @neo.create_node("name" => "Peter") + new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"weight" => 5}) + existing_rels = @neo.find_relationship_auto_index("weight", 5) + existing_rels.collect{|n| n["self"]}.include?(new_relationship["self"]).should be_true end it "can query a relationship from an automatic index" do - pending + new_node1 = @neo.create_node("name" => "Max") + new_node2 = @neo.create_node("name" => "Peter") + new_relationship = @neo.create_relationship("friends", new_node1, new_node2, {"weight" => 5}) + existing_rels = @neo.find_relationship_auto_index("weight:5") + existing_rels.collect{|n| n["self"]}.include?(new_relationship["self"]).should be_true end end