Description
In a QA functional test, we were trying to set the coordinate system to
wgs84/double
in a RegionPathIndex and the test throws exception when a search is executed.
REST and XQuery supports "wgs84/double" coordinate system. But client APIs do not. However on NodeJS client they have a method on query builder to provide the coordinate system as an option. See the NodeJS script below for
q.coordSystem('wgs84/double')
Here is a NodeJS test script that sets this option in the builder.
var q = marklogic.queryBuilder;
...
...
..
it('TEST 3 - geospatial region box contains polygon', function(done){
dbWriter.documents.query(
q.where(
q.geospatialRegion(
q.geoPath('/root/item/box', q.coordSystem('wgs84/double')),
'contains',
q.polygon(q.point(-5, -70), q.point(4, -70), q.point(3, -60), q.point(-3, -65), q.point(-5, -70))
)
)
).
result(function(response) {
//console.log(JSON.stringify(response, null, 2));
response.length.should.equal(2);
response[0].uri.should.equal('/geo/region/test/Equator.xml');
response[1].uri.should.equal('/geo/region/test/Equator-json.json');
done();
}, done);
Now executing a Java test after a range index of this type has been setup for a database will not work and could throw an exception.
The REST payload used to create the GeoSpatial Region Path Index is
"geospatial-region-path-index":
* [
{
"path-expression": "/root/item/box",
"coordinate-system": "wgs84/double",
"geohash-precision": 2,
"invalid-values": "reject"
}
]
The Java test used is
public void testBoxContainsPolygon() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException, TransformerException
{
System.out.println("Running testBoxContainsPolygon");
client = getDatabaseClient("rest-admin", "x", Authentication.DIGEST);
QueryManager queryMgr = client.newQueryManager();
// create query def
StructuredQueryBuilder qb = queryMgr.newStructuredQueryBuilder();
StructuredQueryDefinition t = qb.geospatial(qb.geoRegionPath(qb.pathIndex("/root/item/box")), GeoSpatialOperator.CONTAINS,
qb.polygon(qb.point(-5,-70), qb.point(4, -70), qb.point(3, -60), qb.point(-3, -65), qb.point(-5,-70)));
// create handle
JacksonHandle resultsHandle = new JacksonHandle();
queryMgr.search(t, resultsHandle);
// get the result
JsonNode resultNode = resultsHandle.get();
JsonNode jsonPointNodes = resultNode.path("results");
// Should have 2 nodes returned.
assertEquals("Two nodes not returned from testCircleContainsCircle method ", 2, resultNode.path("total").asInt());
assertTrue("URI returned from testCircleContainsCircle method is incorrect", jsonPointNodes.get(0).path("uri").asText().contains("/Equator-json.json") ||
jsonPointNodes.get(1).path("uri").asText().contains("/Equator-json.json"));
assertTrue("URI returned from testCircleContainsCircle method is incorrect", jsonPointNodes.get(0).path("uri").asText().contains("/Equator.xml") ||
jsonPointNodes.get(1).path("uri").asText().contains("/Equator.xml"));
client.release();
}
Using the wgs84/double coordinate system in Java Test, the test throws an exception while doing the search.
com.marklogic.client.FailedRequestException: Local message: search failed: Internal Server Error. Server Message: XDMP-GEOREGIONIDX-NOTFOUND: cts:geospatial-region-path-reference("/root/item/box", "coordinate-system=wgs84") -- /root/item/box wgs84 . See the MarkLogic server error log for further detail.
at com.marklogic.client.impl.JerseyServices$JerseySearchRequest.getResponse(JerseyServices.java:2221)
at com.marklogic.client.impl.JerseyServices.search(JerseyServices.java:1990)
at com.marklogic.client.impl.QueryManagerImpl.search(QueryManagerImpl.java:199)
at com.marklogic.client.impl.QueryManagerImpl.search(QueryManagerImpl.java:163)
at com.marklogic.client.functionaltest.TestDoublePrecisionGeoOps.testBoxContainsPolygon(TestDoublePrecisionGeoOps.java:182)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
The StructuredQueryBuilder class does not have a method to set coordinate system just like the script in NodeJS client. We need a similar method to set it as an option for the query on the builder.