Skip to content

Commit

Permalink
add add_node_to_index method
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Jan 27, 2014
1 parent 0a360d9 commit ab0bc96
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,10 @@ def create_spatial_index(name, type = nil, lat = nil, lon = nil)
@spatial.create_spatial_index(name, type, lat, lon)
end

def add_node_to_spatial_index(index, id)
@spatial.add_node_to_spatial_index(index, id)
end

# clean database

# For testing (use a separate neo4j instance)
Expand Down
13 changes: 13 additions & 0 deletions lib/neography/rest/spatial.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Spatial
add_path :find_geometries_in_bbox, "/ext/SpatialPlugin/graphdb/findGeometriesInBBox"
add_path :find_geometries_within_distance,"/ext/SpatialPlugin/graphdb/findGeometriesWithinDistance"
add_path :create_index, "/index/node"
add_path :add_to_index, "/index/node/:index"

def initialize(connection)
@connection = connection
Expand Down Expand Up @@ -136,6 +137,18 @@ def create_spatial_index(name, type, lat, lon)
@connection.post(create_index_path, options)
end

def add_node_to_spatial_index(index, id)
options = {
:body => {
:uri => @connection.configuration + "/node/#{get_id(id)}",
:key => "k",
:value => "v"
}.to_json,
:headers => json_content_type.merge({'Accept' => 'application/json;charset=UTF-8'})
}
@connection.post(add_to_index_path(:index => index), options)
end

end
end
end
25 changes: 25 additions & 0 deletions spec/integration/rest_spatial_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@
existing_node["data"][0][0]["data"]["lat"].should == properties[:lat]
existing_node["data"][0][0]["data"]["lon"].should == properties[:lon]
end

it "can find a geometry in a bounding box using cypher two" do
properties = {:lat => 60.1, :lon => 15.2}
@neo.create_spatial_index("geombbcypher2", "point", "lat", "lon")
node = @neo.create_node(properties)
added = @neo.add_node_to_spatial_index("geombbcypher2", node)
existing_node = @neo.execute_query("start node = node:geombbcypher2('bbox:[15.0,15.3,60.0,60.2]') return node")
existing_node.should_not be_empty
existing_node["data"][0][0]["data"]["lat"].should == properties[:lat]
existing_node["data"][0][0]["data"]["lon"].should == properties[:lon]
end

end

describe "find geometries within distance" do
Expand All @@ -136,6 +148,19 @@
existing_node["data"][0][0]["data"]["lat"].should == properties[:lat]
existing_node["data"][0][0]["data"]["lon"].should == properties[:lon]
end

it "can find a geometry within distance using cypher 2" do
properties = {:lat => 60.1, :lon => 15.2}
@neo.create_spatial_index("geowdcypher2", "point", "lat", "lon")
node = @neo.create_node(properties)
added = @neo.add_node_to_spatial_index("geowdcypher2", node)
existing_node = @neo.execute_query("start n = node:geowdcypher2({bbox}) return n", {:bbox => "withinDistance:[60.0,15.0,100.0]"})
existing_node.should_not be_empty
existing_node.should_not be_empty
existing_node["data"][0][0]["data"]["lat"].should == properties[:lat]
existing_node["data"][0][0]["data"]["lon"].should == properties[:lon]
end

end

end

0 comments on commit ab0bc96

Please sign in to comment.