@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()); } }
@Override public int getJobInstanceCount(String jobName) throws NoSuchJobException { StructuredQueryBuilder qb = new StructuredQueryBuilder(SEARCH_OPTIONS_NAME); StructuredQueryDefinition querydef = qb.and( qb.valueConstraint("jobName", jobName), qb.collection(COLLECTION_JOB_INSTANCE) ); QueryManager queryMgr = databaseClient.newQueryManager(); SearchHandle results = queryMgr.search(querydef, new SearchHandle()); int count = (int) results.getTotalResults(); if (count == 0) { throw new NoSuchJobException(jobName + " not found"); } else { return count; } }
@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); }
private RawStructuredQueryDefinition allButCollectors() { StructuredQueryBuilder sqb = jobClient.newQueryManager().newStructuredQueryBuilder(); RawStructuredQueryDefinition allButCollectors = sqb.build( sqb.and( sqb.containerQuery(sqb.element("trace"), sqb.not(sqb.value(sqb.jsonProperty("label"), "collector"))))); return allButCollectors; }
@SuppressWarnings("deprecation") @Test public void testBuilder() throws IOException, SAXException, ParserConfigurationException { StructuredQueryBuilder qb = new StructuredQueryBuilder(); StructuredQueryDefinition t, u, v, m; t = qb.and(qb.term("one"), qb.term("two"), qb.term("three")); for (String q: new String[]{t.serialize(), qb.build(t).toString()}) { xml = new StringInputStream(q); parser.parse(xml, handler); u = qb.or(qb.term("one"), qb.term("two"), qb.term("three")); for (String q: new String[]{u.serialize(), qb.build(u).toString()}) { xml = new StringInputStream(q); parser.parse(xml, handler); v = qb.or(t, u); for (String q: new String[]{v.serialize(), qb.build(v).toString()}) { xml = new StringInputStream(q); parser.parse(xml, handler); t = qb.and(qb.term("one", "two", "three")); for (String q: new String[]{t.serialize(), qb.build(t).toString()}) { xml = new StringInputStream(q); parser.parse(xml, handler); t = qb.and(qb.term(3.0, "one", "two", "three")); for (String q: new String[]{t.serialize(), qb.build(t).toString()}) { xml = new StringInputStream(q); parser.parse(xml, handler);
@Test public void testStructuredQuery() throws Exception { StructuredQueryDefinition query = new StructuredQueryBuilder().collection(qhbTestCollection); Map<String, String[]> matchesByForest = new HashMap<>(); matchesByForest.put("java-unittest-1", new String[] {uri1, uri3, uri4}); matchesByForest.put("java-unittest-2", new String[] {uri5}); matchesByForest.put("java-unittest-3", new String[] {uri2}); runQueryBatcher(moveMgr.newQueryBatcher(query), query, matchesByForest, 1, 2); }
StructuredQueryBuilder sqb = new StructuredQueryBuilder(); StructuredQueryDefinition query = sqb.and( sqb.collection(collection), sqb.value(sqb.jsonProperty("type"), "X"), sqb.value(sqb.jsonProperty("originJurisdiction"), "Y"), sqb.value(sqb.jsonProperty("state"), "resolved", "closed", "finalized"), sqb.not( sqb.value(sqb.jsonProperty("hold"), "true") ), sqb.range( sqb.jsonProperty("lastModified"), "xs:dateTime", new String[0], Operator.LE, sevenYearsAgo
XMLDocumentManager docMgr = client.newXMLDocumentManager(); DOMHandle results = new DOMHandle(); StructuredQueryBuilder qb = new StructuredQueryBuilder(); StructuredQueryDefinition qd = qb.and(qb.term("much", "thought")); Transaction t = client.openTransaction(); try {
@Test public void test105Searches() throws IOException { QueryManager queryMgr = Common.client.newQueryManager(); StructuredQueryBuilder qb = queryMgr.newStructuredQueryBuilder(); for (int i=0;i<105;i++) { for (QueryDefinition t : new QueryDefinition[] { qb.term("leaf3"), qb.build(qb.value(qb.element("leaf"), "leaf3")) }) { JacksonHandle results = queryMgr.search(t, new JacksonHandle()); assertNotNull(results); JsonNode jsonResults =results.get(); @SuppressWarnings("unused") String resultString = results.getMapper().writeValueAsString(jsonResults); // ignore. } } }
@Test public void testPrematureStopQueryJob() { // this test can't actually validate that the message is printed, so a human // must check the logging output // Expected something like: // 18:20:33.607 [main] WARN c.m.c.d.impl.QueryBatcherImpl - QueryBatcher instance "unnamed" stopped before all results were retrieved StructuredQueryDefinition query = new StructuredQueryBuilder().and(); QueryBatcher batcher = moveMgr.newQueryBatcher(query); moveMgr.stopJob(batcher); }
StructuredQueryDefinition query1 = qb.and(qb.collectionConstraint("coll", "set1"), qb.collectionConstraint("coll", "set5")); StructuredQueryDefinition query2 = qb.not(qb.wordConstraint("intitle", "memex")); StructuredQueryDefinition query3 = qb.valueConstraint("id", "**11"); StructuredQueryDefinition query4 = qb.rangeConstraint("date", StructuredQueryBuilder.Operator.EQ, "2005-01-01"); StructuredQueryDefinition query5 = qb.and(qb.wordConstraint("para", "Bush"), qb.not(qb.wordConstraint("para", "memex"))); StructuredQueryDefinition query6 = qb.rangeConstraint("price", StructuredQueryBuilder.Operator.EQ, "low"); StructuredQueryDefinition query7 = qb.or(qb.rangeConstraint("pop", StructuredQueryBuilder.Operator.EQ, "high"), qb.rangeConstraint("pop", StructuredQueryBuilder.Operator.EQ, "medium")); StructuredQueryDefinition queryFinal = qb.and(query1, query2, query3, query4, query5, query6, query7);
StringBuilder failures; try (FileWriter writer = new FileWriter(tempFile)) { StructuredQueryBuilder sqb = new StructuredQueryBuilder(); StructuredQueryDefinition query = sqb.value(sqb.jsonProperty("dept"), "HR"); query.setCollections(qhbTestCollection); successDocs1 = new AtomicInteger(0);
@Test public void testBug22037() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException, TransformerException { System.out.println("Running testBug22037"); String[] filenames = { "constraint1.xml", "constraint2.xml", "constraint3.xml", "constraint4.xml", "constraint5.xml" }; String queryOptionName = "rangeConstraintIntOpt.xml"; DatabaseClient client = getDatabaseClient("rest-admin", "x", getConnType()); // write docs for (String filename : filenames) { writeDocumentUsingInputStreamHandle(client, filename, "/range-constraint/", "XML"); } setQueryOption(client, queryOptionName); QueryManager queryMgr = client.newQueryManager(); StructuredQueryBuilder qb = queryMgr.newStructuredQueryBuilder(queryOptionName); StructuredQueryDefinition rangeQuery = qb.range(qb.element("popularity"), "xs:int", Operator.GE, 4); // create handle DOMHandle resultsHandle = new DOMHandle(); queryMgr.search(rangeQuery, resultsHandle); // get the result Document resultDoc = resultsHandle.get(); // System.out.println(convertXMLDocumentToString(resultDoc)); assertXpathEvaluatesTo("4", "string(//*[local-name()='result'][last()]//@*[local-name()='index'])", resultDoc); // release client client.release(); }
@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 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); }
StructuredQueryDefinition t = qb.value(qb.elementAttribute(qb.element(new QName("http://cloudbank.com", "price")), qb.attribute("amt")), "0.1");
@Test public void testMatchOneAndThrowException() { StructuredQueryDefinition query = new StructuredQueryBuilder().document(uri1); List<String> urisIterator = testQueryExceptions(query, 1, 0); testIteratorExceptions(urisIterator, 1, 0); }
@Override public JobExecution getJobExecution(Long executionId) { JobExecution jobExec = null; StructuredQueryBuilder qb = new StructuredQueryBuilder(SEARCH_OPTIONS_NAME); StructuredQueryDefinition querydef = qb.rangeConstraint("jobExecutionId", Operator.EQ, executionId.toString()); QueryManager queryMgr = databaseClient.newQueryManager(); SearchHandle results = queryMgr.search(querydef, new SearchHandle()); if (results.getTotalResults() > 0L) { MatchDocumentSummary[] summaries = results.getMatchResults(); JAXBHandle<MarkLogicJobInstance> handle = new JAXBHandle<>(jaxbContext()); MarkLogicJobInstance mji = summaries[0].getFirstSnippet(handle).get(); if (mji.getJobExecutions().size() >= 1) { for (JobExecution je : mji.getJobExecutions()) { if (je.getId().equals(executionId)) { jobExec = je; } } } } return jobExec; }