@Override public StructuredQueryDefinition geospatial(GeospatialIndex index, String[] options, Region... regions) { return super.geospatial(index, StructuredQueryBuilder.FragmentScope.DOCUMENTS, options, regions); } @Override
StructuredQueryDefinition t = qb.geospatial(qb.geoRegionPath(qb.pathIndex("/root/item/circle"), CoordinateSystem.WGS84DOUBLE), GeospatialOperator.INTERSECTS, qb.point(0, -66.09375));
@Test public void testPolygonTouchesPoint() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException, TransformerException { System.out.println("Running testPolygonTouchesPoint"); QueryManager queryMgr = client.newQueryManager(); // create query def StructuredQueryBuilder qb = queryMgr.newStructuredQueryBuilder(); StructuredQueryDefinition t = qb.geospatial(qb.geoRegionPath(qb.pathIndex("/root/item/polygon")), GeospatialOperator.TOUCHES, qb.point(-26.0, 100.89) ); // 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 testPolygonTouchesPoint method ", 2, resultNode.path("total").asInt()); String exptdString = "POLYGON((153.65 -8.35,170.57 -26.0,162.52 -52.52,136.0 -56.35,111.0 -51.0,100.89 -26.0,108.18 1.82,136.0 10.26,153.65 -8.35))"; String polygondesc1 = jsonPointNodes.get(0).path("matches").get(0).path("match-text").get(0).path("highlight").asText(); String polygondesc2 = jsonPointNodes.get(1).path("matches").get(0).path("match-text").get(0).path("highlight").asText(); assertTrue("Polygon Node not returned from testPolygonTouchesPoint method ", exptdString.equalsIgnoreCase(polygondesc1)); assertTrue("Polygon Node not returned from testPolygonTouchesPoint method ", exptdString.equalsIgnoreCase(polygondesc2)); }
@Test public void testCircleContainsCircle() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException, TransformerException { System.out.println("Running testCircleContainsCircle"); QueryManager queryMgr = client.newQueryManager(); // create query def StructuredQueryBuilder qb = queryMgr.newStructuredQueryBuilder(); StructuredQueryDefinition t = qb.geospatial(qb.geoRegionPath(qb.pathIndex("/root/item/circle"), CoordinateSystem.WGS84DOUBLE), GeospatialOperator.CONTAINS, qb.circle(qb.point(0, -66.09375), 6.897)); // 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")); }
@Test public void testBoxContainsPolygon() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException, TransformerException { System.out.println("Running testBoxContainsPolygon"); QueryManager queryMgr = client.newQueryManager(); // create query def StructuredQueryBuilder qb = queryMgr.newStructuredQueryBuilder(); StructuredQueryDefinition t = qb.geospatial(qb.geoRegionPath(qb.pathIndex("/root/item/box"), CoordinateSystem.WGS84DOUBLE), 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 testBoxContainsPolygon method ", 2, resultNode.path("total").asInt()); assertTrue("URI returned from testBoxContainsPolygon 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 testBoxContainsPolygon method is incorrect", jsonPointNodes.get(0).path("uri").asText().contains("/Equator.xml") || jsonPointNodes.get(1).path("uri").asText().contains("/Equator.xml")); }
StructuredQueryDefinition t = qb.geospatial(qb.geoRegionPath(qb.pathIndex("/root/item/circle"), CoordinateSystem.WGS84DOUBLE), GeospatialOperator.COVEREDBY, qb.polygon(qb.point(40.13, -52.96), qb.point(40.45, -36.61), qb.point(38.16, -13.48),
StructuredQueryDefinition t = qb.geospatial(qb.geoRegionPath(qb.pathIndex("/root/item/linestring"), CoordinateSystem.WGS84DOUBLE), GeospatialOperator.CONTAINS, qb.point(2.85526278436658, -80.5078125));
StructuredQueryDefinition t = qb.geospatial(qb.geoRegionPath(qb.pathIndex("/root/item/circle"), CoordinateSystem.WGS84DOUBLE), GeospatialOperator.WITHIN, qb.box(-6, 30, 100, 150)
StructuredQueryDefinition t = qb.geospatial(qb.geoRegionPath(qb.pathIndex("/root/item/box"), CoordinateSystem.WGS84DOUBLE), GeospatialOperator.OVERLAPS, qb.circle(qb.point(25.234, 85.2345), 10)
StructuredQueryDefinition t = qb.geospatial(qb.geoRegionPath(qb.pathIndex("/root/item/box"), CoordinateSystem.WGS84DOUBLE), GeospatialOperator.COVERS, qb.polygon(qb.point(-5, -70), qb.point(4, -70), qb.point(3, -60),
@Ignore public void testLinestringCrossesBox() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException, TransformerException { System.out.println("Running testLinestringCrossesBox"); QueryManager queryMgr = client.newQueryManager(); // create query def StructuredQueryBuilder qb = queryMgr.newStructuredQueryBuilder(); StructuredQueryDefinition t = qb.geospatial(qb.geoRegionPath(qb.pathIndex("/root/item/linestring"), CoordinateSystem.WGS84DOUBLE), GeospatialOperator.CROSSES, qb.box(-5.45, -76.35643, 5.35, -54.636) ); // create handle JacksonHandle resultsHandle = new JacksonHandle(); queryMgr.search(t, resultsHandle); // get the result JsonNode resultNode = resultsHandle.get(); // Should have 2 nodes returned. assertEquals("Two nodes not returned from testPolygonCoversBox method ", 2, resultNode.path("total").asInt()); }
@Test public void testPolygonDisjointPolygon() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException, TransformerException { System.out.println("Running testPolygonDisjointPolygon"); QueryManager queryMgr = client.newQueryManager(); queryMgr.setPageLength(50); // create query def StructuredQueryBuilder qb = queryMgr.newStructuredQueryBuilder(); StructuredQueryDefinition t = qb.geospatial(qb.geoRegionPath(qb.pathIndex("/root/item/polygon"), CoordinateSystem.WGS84), GeospatialOperator.DISJOINT, qb.polygon( qb.point(-90, 131), qb.point(-85, 133), qb.point(-87, 134), qb.point(-88, 135), qb.point(-90, 131)) ); // create handle JacksonHandle resultsHandlejh = new JacksonHandle(); queryMgr.search(t, resultsHandlejh); // get the result JsonNode resultNodejh = resultsHandlejh.get(); // Should have 20 nodes returned. assertEquals("Twenty nodes not returned from testPolygonCoversBox method ", 20, resultNodejh.path("total").asInt()); }
StructuredQueryDefinition geoQuery = qb.geospatial(qb.geoPath(qb.pathIndex("/doc/g-elem-point")), qb.box(-12, -5, -11, -4)); Collection<String> nameSpaceCollection = qb.getNamespaces().getAllPrefixes(); assertEquals("getNamespace failed ", false, nameSpaceCollection.isEmpty());
@Ignore public void testGeospatialRegionQuery() { QueryManager queryMgr = Common.client.newQueryManager(); StructuredQueryBuilder qb = new StructuredQueryBuilder(); StructuredQueryDefinition qdef; qdef = qb.geospatial(qb.geoRegionPath(qb.pathIndex("/country/region")), GeospatialOperator.CONTAINS, qb.point(19.429297983081977, -99.140625)); SearchHandle results = queryMgr.search(qdef, new SearchHandle()); MatchDocumentSummary[] summaries = results.getMatchResults(); for (MatchDocumentSummary summary : summaries) { assertEquals("mexico.xml", summary.getUri()); } }
@Ignore public void testDoublePrecisionCoordinateSystem() { QueryManager queryMgr = Common.client.newQueryManager(); StructuredQueryBuilder qb = new StructuredQueryBuilder(); String options[] = new String[1]; options[0] = "coordinate-system=wgs84/double"; StructuredQueryDefinition qdef; qdef = qb.geospatial(qb.geoElementPair(qb.element("point"), qb.element("lat"), qb.element("lon")), null, options, qb.box(0, 0, 10, 10)); SearchHandle results = queryMgr.search(qdef, new SearchHandle()); MatchDocumentSummary[] summaries = results.getMatchResults(); assertEquals(1, summaries.length); }
@Ignore public void testFloatPrecisionCoordinateSystem() { QueryManager queryMgr = Common.client.newQueryManager(); StructuredQueryBuilder qb = new StructuredQueryBuilder(); String options[] = new String[1]; options[0] = "coordinate-system=wgs84"; StructuredQueryDefinition qdef; qdef = qb.geospatial(qb.geoElementPair(qb.element("point"), qb.element("lat"), qb.element("lon")), null, options, qb.box(0, 0, 10, 10)); SearchHandle results = queryMgr.search(qdef, new SearchHandle()); MatchDocumentSummary[] summaries = results.getMatchResults(); assertEquals(2, summaries.length); }
@Ignore public void testFloatPrecision() { QueryManager queryMgr = Common.client.newQueryManager(); StructuredQueryBuilder qb = new StructuredQueryBuilder(); String options[] = new String[1]; options[0] = "precision=float"; StructuredQueryDefinition qdef; qdef = qb.geospatial(qb.geoElementPair(qb.element("point"), qb.element("lat"), qb.element("lon")), null, options, qb.box(0, 0, 10, 10)); SearchHandle results = queryMgr.search(qdef, new SearchHandle()); MatchDocumentSummary[] summaries = results.getMatchResults(); assertEquals(2, summaries.length); }
@Ignore public void testDoublePrecision() { QueryManager queryMgr = Common.client.newQueryManager(); StructuredQueryBuilder qb = new StructuredQueryBuilder(); String options[] = new String[1]; options[0] = "precision=double"; StructuredQueryDefinition qdef; qdef = qb.geospatial(qb.geoElementPair(qb.element("point"), qb.element("lat"), qb.element("lon")), null, options, qb.box(0, 0, 10, 10)); SearchHandle results = queryMgr.search(qdef, new SearchHandle()); MatchDocumentSummary[] summaries = results.getMatchResults(); assertEquals(1, summaries.length); }
qdef = qb.geospatial(qb.geoRegionPath(qb.pathIndex("/country/region"), CoordinateSystem.WGS84DOUBLE), GeospatialOperator.COVERS, qb.point(10.00000003, 10.00000003)); SearchHandle results = queryMgr.search(qdef, new SearchHandle()); assertEquals(0, summaries.length); qdef = qb.geospatial(qb.geoRegionPath(qb.pathIndex("/country/region"), CoordinateSystem.WGS84), GeospatialOperator.COVERS, qb.point(10.00000003, 10.00000003)); results = queryMgr.search(qdef, new SearchHandle()); assertEquals(1, summaries.length); qdef = qb.geospatial(qb.geoRegionPath(qb.pathIndex("/country/region"), CoordinateSystem.getOther("wgs84", true)), GeospatialOperator.COVERS, qb.point(10.00000003, 10.00000003)); results = queryMgr.search(qdef, new SearchHandle()); assertEquals(0, summaries.length); qdef = qb.geospatial(qb.geoRegionPath(qb.pathIndex("/country/region"), CoordinateSystem.getOther("wgs84")), GeospatialOperator.COVERS, qb.point(10.00000003, 10.00000003)); results = queryMgr.search(qdef, new SearchHandle());
@Test public void testStructuredSearch2() throws IOException { QueryManager queryMgr = Common.client.newQueryManager(); EditableNamespaceContext namespaces = new EditableNamespaceContext(); namespaces.put("x", "root.org"); namespaces.put("y", "target.org"); StructuredQueryBuilder qb = new StructuredQueryBuilder(namespaces); StructuredQueryDefinition qdef = qb.geospatial( qb.geoPath(qb.pathIndex("/x:geo/y:path")), qb.box(1, 2, 3, 4)); SearchHandle results = queryMgr.search(qdef, new SearchHandle()); assertNotNull(results); MatchDocumentSummary[] summaries = results.getMatchResults(); assertTrue(summaries == null || summaries.length == 0); }