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), qb.point(21.09, -1.1), qb.point(0.0, -17.46), qb.point(-17.38, -12.52), qb.point(-33.08, -20.47), qb.point(-51.46, -28.61), qb.point(-65.33, -44.77), qb.point(-66.8, -66.0), qb.point(-53.99, -83.54), qb.point(-54.35, -105.49), qb.point(-24.59, -99.85), qb.point(-14.58, -110.86), qb.point(-0.0, -127.42), qb.point(13.44, -107.37), qb.point(35.78, -115.25), qb.point(53.21, -104.66), qb.point(48.69, -81.82), qb.point(55.37, -66.0), qb.point(40.13, -52.96)
@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")); }
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 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()); }
GeospatialOperator.CONTAINS, qb.point(2.85526278436658, -80.5078125));
StructuredQueryDefinition t = qb.geospatial(qb.geoRegionPath(qb.pathIndex("/root/item/point"), CoordinateSystem.WGS84), GeospatialOperator.EQUALS, qb.point(0, -66.09375) );
StructuredQueryDefinition t = qb.geospatial(qb.geoRegionPath(qb.pathIndex("/root/item/box"), CoordinateSystem.WGS84DOUBLE), GeospatialOperator.OVERLAPS, qb.circle(qb.point(25.234, 85.2345), 10) );
@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()); } }
t = qb.geospatialConstraint("geo", qb.box(1, 2, 3, 4), qb.circle(0, 0, 100), qb.point(5, 6), qb.polygon(qb.point(1, 2), qb.point(2, 3), qb.point(3, 4), qb.point(4, 1))); for (String q: new String[]{t.serialize(), qb.build(t).toString()}) { xml = new StringInputStream(q); qb.box(1, 2, 3, 4), qb.circle(0, 0, 100), qb.point(5, 6), qb.polygon(qb.point(1, 2), qb.point(2, 3), qb.point(3, 4), qb.point(4, 1))); for (String q: new String[]{qb.build(m).toString()}) { xml = new StringInputStream(q); FragmentScope.DOCUMENTS, new String[] {"score-function=linear", "scale-factor=2.0"}, qb.box(1, 2, 3, 4), qb.circle(0, 0, 100), qb.point(5, 6), qb.polygon(qb.point(1, 2), qb.point(2, 3), qb.point(3, 4), qb.point(4, 1))); for (String q: new String[]{qb.build(m).toString()}) { xml = new StringInputStream(q); assertXMLEqual("<query xmlns=\"http://marklogic.com/appservices/search\">" + "<value-constraint-query><constraint-name>name</constraint-name><text>one</text></value-constraint-query></query>", inner); inner = qb.point(5, 6).serialize(); assertXMLEqual("<query xmlns=\"http://marklogic.com/appservices/search\">" + "<point><latitude>5.0</latitude><longitude>6.0</longitude></point></query>", inner);
StructuredQueryDefinition qdef; qdef = qb.geospatialRegionConstraint("geoo", GeospatialOperator.DISJOINT, qb.point(19.429297983081977, -99.140625)); assertEquals(3, summaries.length); qdef = qb.geospatialRegionConstraint("geoo", GeospatialOperator.CONTAINS, qb.point(21.884239, -78.164978)); results = queryMgr.search(qdef, new SearchHandle()); summaries = results.getMatchResults();
qb.point(10.00000003, 10.00000003)); SearchHandle results = queryMgr.search(qdef, new SearchHandle()); MatchDocumentSummary[] summaries = results.getMatchResults(); qb.point(10.00000003, 10.00000003)); results = queryMgr.search(qdef, new SearchHandle()); summaries = results.getMatchResults(); qb.point(10.00000003, 10.00000003)); results = queryMgr.search(qdef, new SearchHandle()); summaries = results.getMatchResults(); qb.point(10.00000003, 10.00000003)); results = queryMgr.search(qdef, new SearchHandle()); summaries = results.getMatchResults();
StructuredQueryDefinition geoElementConstraintQuery = qb.geospatialConstraint("geo-elem", qb.point(12, 5)); StructuredQueryDefinition termQuery = qb.term("bill_kara"); StructuredQueryDefinition finalOrQuery = qb.or(geoElementConstraintQuery, termQuery);
@Ignore public void testGeospatialRegionQueryConstraint() { QueryManager queryMgr = Common.client.newQueryManager(); StructuredQueryBuilder qb = queryMgr.newStructuredQueryBuilder(); StructuredQueryDefinition qdef; String options = "<options xmlns=\"http://marklogic.com/appservices/search\">" + " <constraint name='geo'>" + " <geo-region-path coord='wgs84'>" + " <path-index>/country/region</path-index>" + " </geo-region-path>" + " </constraint>" + "</options>"; qdef = qb.geospatialRegionConstraint("geo", GeospatialOperator.CONTAINS, qb.point(19.429297983081977, -99.140625)); String combinedQuery = "<search xmlns=\"http://marklogic.com/appservices/search\">" + qdef.serialize() + options + "</search>"; RawCombinedQueryDefinition query = queryMgr.newRawCombinedQueryDefinition(new StringHandle(combinedQuery)); SearchHandle results = queryMgr.search(query, new SearchHandle()); MatchDocumentSummary[] summaries = results.getMatchResults(); assertEquals(1, summaries.length); for (MatchDocumentSummary summary : summaries) { assertEquals("mexico.xml", summary.getUri()); } }