From ab0bc965324a49f42cbb9f861bf9b0eb82010011 Mon Sep 17 00:00:00 2001 From: Max De Marzi Date: Mon, 27 Jan 2014 12:35:18 -0600 Subject: [PATCH] add add_node_to_index method --- lib/neography/rest.rb | 4 ++++ lib/neography/rest/spatial.rb | 13 +++++++++++++ spec/integration/rest_spatial_spec.rb | 25 +++++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index 7f64e87..219ec1e 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -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) diff --git a/lib/neography/rest/spatial.rb b/lib/neography/rest/spatial.rb index 9790da5..0649522 100644 --- a/lib/neography/rest/spatial.rb +++ b/lib/neography/rest/spatial.rb @@ -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 @@ -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 \ No newline at end of file diff --git a/spec/integration/rest_spatial_spec.rb b/spec/integration/rest_spatial_spec.rb index 3740435..743c9fd 100644 --- a/spec/integration/rest_spatial_spec.rb +++ b/spec/integration/rest_spatial_spec.rb @@ -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 @@ -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 \ No newline at end of file