我正在努力让Neo4j空间插件正常工作。但是,当我尝试通过REST在插件URI中查询或者使用cypher时,我得不到任何结果,即使我将距离设置为数百万公里。我查看了Neo4j Spatial 'WithinDistance' Cypher query returns empty while REST call returns data,它有类似的问题并且正在为节点编制索引,但仍然没有快乐。有人可以看看下面的代码并告诉我这是什么问题?感谢。
private void checkSpatialDB() {
Client client = ClientBuilder.newClient();
WebTarget target = client.target(SERVER_ROOT_URI + "ext/SpatialPlugin");
Response response = target.request(MediaType.APPLICATION_JSON)
.get(Response.class);
System.out.println(String.format("Spatial Plugin data:\n" + System.getProperty("line.separator") + "%s",
response.readEntity(String.class)));
response.close();
}
private void addSpatialDataTest() {
String layerProperties = "{ \"layer\" : \"geom\", \"lat\" : \"lat\", \"lon\" : \"lon\" }";
Client client = ClientBuilder.newClient();
WebTarget target = client.target(SERVER_ROOT_URI + "ext/SpatialPlugin/graphdb/addSimplePointLayer");
Response response = target.request(MediaType.APPLICATION_JSON)
.post(Entity.entity(layerProperties, MediaType.APPLICATION_JSON));
System.out.println(String.format("Add geometry layer:\n" + System.getProperty("line.separator") + "%s",
response.readEntity(String.class)));
response.close();
// Now add a spatial index
String indexProperties = "{ \"name\" : \"geom\", \"config\" : {"
+ "\"provider\" : \"spatial\", \"geometry_type\" : \"point\", \"lat\" : \"lat\","
+ "\"lon\" : \"lon\" } }";
client = ClientBuilder.newClient();
target = client.target(SERVER_ROOT_URI + "index/node/");
response = target.request(MediaType.APPLICATION_JSON)
.post(Entity.entity(indexProperties, MediaType.APPLICATION_JSON));
System.out.println(String.format("Add geometry index:\n" + System.getProperty("line.separator") + "%s",
response.readEntity(String.class)));
response.close();
// Now add a spatial node
String yeovil = "{ \"lat\" : 50.9, \"lon\" : -2.6 }";
client = ClientBuilder.newClient();
target = client.target(SERVER_ROOT_URI + "node");
response = target.request(MediaType.APPLICATION_JSON)
.post(Entity.entity(yeovil, MediaType.APPLICATION_JSON));
URI newNode = response.getLocation();
System.out.println(String.format("Add node for Yeovil:\n" + System.getProperty("line.separator") + "%s"
+ "URI for new node [%s]",
response.readEntity(String.class), newNode));
response.close();
// Add the created node to the spatial layer
String addToLayer = "{ \"layer\" : \"geom\", \"node\" : \"" + newNode + "\" }";
client = ClientBuilder.newClient();
target = client.target(SERVER_ROOT_URI + "ext/SpatialPlugin/graphdb/addNodeToLayer");
response = target.request(MediaType.APPLICATION_JSON)
.post(Entity.entity(addToLayer, MediaType.APPLICATION_JSON));
System.out.println(String.format("Add node to spatial layer:\n" + System.getProperty("line.separator") + "%s",
response.readEntity(String.class)));
response.close();
// Add the created node to the geom index
String addToIndex = "{ \"key\" : \"noKey\", \"value\" : \"noValue\", \"uri\" : \"" + newNode + "\" }";
client = ClientBuilder.newClient();
target = client.target(SERVER_ROOT_URI + "index/node/geom");
response = target.request(MediaType.APPLICATION_JSON)
.post(Entity.entity(addToIndex, MediaType.APPLICATION_JSON));
response.close();
// Now add another spatial node
String rayleigh = "{ \"lat\" : 51.6, \"lon\" : 0.6 }";
client = ClientBuilder.newClient();
target = client.target(SERVER_ROOT_URI + "node");
response = target.request(MediaType.APPLICATION_JSON)
.post(Entity.entity(rayleigh, MediaType.APPLICATION_JSON));
URI anotherNode = response.getLocation();
System.out.println(String.format("Add node for Yeovil:\n" + System.getProperty("line.separator") + "%s"
+ "URI for new node [%s]",
response.readEntity(String.class), anotherNode));
// Add the created node to the spatial layer
String addAnotherToLayer = "{ \"layer\" : \"geom\", \"node\" : \"" + anotherNode + "\" }";
client = ClientBuilder.newClient();
target = client.target(SERVER_ROOT_URI + "ext/SpatialPlugin/graphdb/addNodeToLayer");
response = target.request(MediaType.APPLICATION_JSON)
.post(Entity.entity(addAnotherToLayer, MediaType.APPLICATION_JSON));
System.out.println(String.format("Add node to spatial layer:\n" + System.getProperty("line.separator") + "%s",
response.readEntity(String.class)));
response.close();
// Add the created node to the geom index
String addAnotherToIndex = "{ \"key\" : \"noKey\", \"value\" : \"noValue\", \"uri\" : \"" + anotherNode + "\" }";
client = ClientBuilder.newClient();
target = client.target(SERVER_ROOT_URI + "index/node/geom");
response = target.request(MediaType.APPLICATION_JSON)
.post(Entity.entity(addAnotherToIndex, MediaType.APPLICATION_JSON));
System.out.println(response.readEntity(String.class));
response.close();
}
private void findSpatialNode() {
// Find nodes within 135km of Portsmouth - should be Yeovil
// String queryString = "{ \"layer\" : \"geom\", \"pointX\" : 50.8, \"pointY\" : -1.1, \"distanceInKm\" : 1350 }";
String queryString = "{ \"query\" : \"start n=node:geom('withinDistance:[50.8, -1.1, 500.0]') return n\" }";
Client client = ClientBuilder.newClient();
WebTarget target = client.target(SERVER_ROOT_URI + "cypher");
Response response = target.request(MediaType.APPLICATION_JSON)
.post(Entity.entity(queryString, MediaType.APPLICATION_JSON));
System.out.println(String.format("Sent query [%s], status code [%d]\nShould just get Yeovil in search result:"
+ System.getProperty("line.separator") + "%s", queryString, response.getStatus(),
response.readEntity(String.class)));
response.close();
}