Skip to content

Commit

Permalink
finding nodes and relationships through query. Remote Groovy script t…
Browse files Browse the repository at this point in the history
…hrough Gremlin plugin ext
  • Loading branch information
lordkada committed Oct 24, 2011
1 parent 1097667 commit bc49b90
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ To Use:
@neo.remove_node_from_index(index, node1) # removes a node from the index
@neo.get_node_index(index, key, value) # exact query of the node index with the given key/value pair
@neo.find_node_index(index, key, value) # advanced query of the node index with the given key/value pair
@neo.find_node_index(index, query ) # advanced query of the node 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.add_relationship_to_index(index, key, value, rel1) # adds a relationship to the index with the given key/value pair
Expand All @@ -106,6 +107,8 @@ To Use:
@neo.remove_relationship_from_index(index, rel1) # removes a relationship from the index
@neo.get_relationship_index(index, key, value) # exact query of the relationship index with the given key/value pair
@neo.find_relationship_index(index, key, value) # advanced query of the relationship index with the given key/value pair
@neo.find_relationship_index(index, query) # advanced query of the relationship index with the given query
@neo.execute_script(script) # sends an arbitrary Groovy script (through the Gremlin plugin)


@neo.get_path(node1, node2, relationships, depth=4, algorithm="shortestPath") # finds the shortest path between two nodes
Expand Down
19 changes: 15 additions & 4 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,11 @@ def get_node_index(index, key, value)
index
end

def find_node_index(index, key, value)
index = get("/index/node/#{index}/#{key}?query=#{value}") || Array.new
def find_node_index(*args)
case args.size
when 3 then index = get("/index/node/#{args[0]}/#{args[1]}?query=#{args[2]}") || Array.new
when 2 then index = get("/index/node/#{args[0]}?query=#{args[1]}") || Array.new
end
return nil if index.empty?
index
end
Expand Down Expand Up @@ -302,8 +305,11 @@ def get_relationship_index(index, key, value)
index
end

def find_relationship_index(index, key, value)
index = get("/index/relationship/#{index}/#{key}?query=#{value}") || Array.new
def find_relationship_index(*args)
case args.size
when 3 then index = get("/index/relationship/#{args[0]}/#{args[1]}?query=#{args[2]}") || Array.new
when 2 then index = get("/index/relationship/#{args[0]}?query=#{args[1]}") || Array.new
end
return nil if index.empty?
index
end
Expand All @@ -328,6 +334,11 @@ def get_paths(from, to, relationships, depth=1, algorithm="allPaths")
paths = post("/node/#{get_id(from)}/paths", options) || Array.new
end

def execute_script(script)
options = { :body => { :script => script } }
post("/ext/GremlinPlugin/graphdb/execute_script", options)
end

private

def evaluate_response(response)
Expand Down
22 changes: 22 additions & 0 deletions spec/integration/rest_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,16 @@
@neo.remove_node_from_index("test_index", key, value, new_node)
end

it "can find a node index using generic query" 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.find_node_index("test_index", "#{key}: #{value}")
new_index.first["self"].should == new_node["self"]
@neo.remove_node_from_index("test_index", key, value, new_node)
end

it "can get a relationship index" do
new_node1 = @neo.create_node
new_node2 = @neo.create_node
Expand Down Expand Up @@ -250,6 +260,18 @@
@neo.remove_relationship_from_index("test_index", key, value, new_relationship)
end

it "can find a relationship index using generic query" 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.find_relationship_index("test_index", "#{key}: #{value}")
new_index.first["self"].should == new_relationship["self"]
@neo.remove_relationship_from_index("test_index", key, value, new_relationship)
end

it "can find use the results of a node index" do
new_node1 = @neo.create_node
new_node2 = @neo.create_node
Expand Down

0 comments on commit bc49b90

Please sign in to comment.