@Override public StructuredQueryBuilder newStructuredQueryBuilder() { return new StructuredQueryBuilder(); } @Override
@Override public StructuredQueryBuilder newStructuredQueryBuilder() { return new StructuredQueryBuilder(); } @Override
@Override public StructuredQueryBuilder newStructuredQueryBuilder(String optionsName) { return new StructuredQueryBuilder(optionsName); }
@Override public StructuredQueryBuilder newStructuredQueryBuilder(String optionsName) { return new StructuredQueryBuilder(optionsName); }
@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); }
@Test public void testCollectionQuery() throws Exception { StructuredQueryDefinition query = new StructuredQueryBuilder().and(); query.setCollections(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, 2, 1); }
@Test public void testDirectoryQuery() throws Exception { StructuredQueryDefinition query = new StructuredQueryBuilder().and(); query.setDirectory("/QueryBatcherTest"); query.setCollections(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, 3, 2); }
@Override public Set<JobExecution> findRunningJobExecutions(String jobName) { StructuredQueryBuilder qb = new StructuredQueryBuilder(SEARCH_OPTIONS_NAME); StructuredQueryDefinition querydef = qb.and(qb.valueConstraint("jobName", jobName)); logger.info(querydef.serialize()); QueryManager queryMgr = databaseClient.newQueryManager(); SearchHandle results = queryMgr.search(querydef, new SearchHandle()); Set<JobExecution> jobExecutions = new HashSet<>(); for ( MatchDocumentSummary summary : results.getMatchResults() ) { JAXBHandle<MarkLogicJobInstance> handle = new JAXBHandle<>(jaxbContext()); summary.getFirstSnippet(handle); MarkLogicJobInstance mji = handle.get(); for (JobExecution je : mji.getJobExecutions()) { if (je.getStatus().isRunning() && je.getEndTime() == null) { jobExecutions.add(je); } } } return jobExecutions; }
@Test public void testMatchOneAndThrowException() { StructuredQueryDefinition query = new StructuredQueryBuilder().document(uri1); List<String> urisIterator = testQueryExceptions(query, 1, 0); testIteratorExceptions(urisIterator, 1, 0); }
@Test public void testMatchNoneAndThrowException() { StructuredQueryDefinition query = new StructuredQueryBuilder().document("nonExistentUri"); List<String> urisIterator = testQueryExceptions(query, 0, 0); testIteratorExceptions(urisIterator, 0, 0); }
@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); }
@Test public void testRuleMatchTransform() { StructuredQueryBuilder qb = new StructuredQueryBuilder(); StructuredQueryDefinition structuredQuery; structuredQuery = qb.rangeConstraint("favorited", Operator.EQ, "true"); ServerTransform transform = new ServerTransform("ruleTransform"); DOMHandle answer = ruleManager.match(structuredQuery, 0L, QueryManager.DEFAULT_PAGE_LENGTH, new String[] {}, new DOMHandle(), transform); Document doc = answer.get(); NodeList nl = doc.getElementsByTagNameNS( "", "transformed-name"); assertEquals(2, nl.getLength()); }
@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; } }
@Test public void testMatchPostQuery() throws SAXException, IOException { StructuredQueryBuilder qb = new StructuredQueryBuilder(); StructuredQueryDefinition structuredQuery; structuredQuery = qb.rangeConstraint("favorited", Operator.EQ, "true"); DOMHandle answer = ruleManager.match(structuredQuery, new DOMHandle()); Document doc = answer.get(); NodeList nl = doc.getElementsByTagNameNS( "http://marklogic.com/rest-api", "name"); assertEquals(2, nl.getLength()); answer = ruleManager.match(structuredQuery, 1, QueryManager.DEFAULT_PAGE_LENGTH, new String[] { "favorites" }, new DOMHandle()); doc = answer.get(); nl = doc.getElementsByTagNameNS("http://marklogic.com/rest-api", "name"); assertEquals(1, nl.getLength()); }
@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 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 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 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); }
@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); }