@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); }
StructuredQueryDefinition termQuery2 = qb.term("Monthly"); StructuredQueryDefinition termQuery3 = qb.term("Bush"); StructuredQueryDefinition andQuery = qb.and(termQuery1, termQuery2); StructuredQueryDefinition andNotFinalQuery = qb.andNot(andQuery, termQuery3); StructuredQueryDefinition termQuery21 = qb.term("Yearly"); StructuredQueryDefinition termQuery31 = qb.term("DT"); StructuredQueryDefinition andQuery1 = qb.and(termQuery11, termQuery21); StructuredQueryDefinition andNotFinalQuery1 = qb.andNot(andQuery1, termQuery31); SearchHandle results = null;
@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); }
qb.and( qb.valueConstraint("jobKey", jobKeyGenerator.generateKey(jobParameters)), qb.valueConstraint("jobName", jobName),
@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 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); }
@Override public List<JobInstance> findJobInstancesByName(String jobName, int start, int count) { List<JobInstance> jobInstances = new ArrayList<>(); QueryManager queryMgr = databaseClient.newQueryManager(); StructuredQueryBuilder qb = new StructuredQueryBuilder(SEARCH_OPTIONS_NAME); StructuredQueryDefinition querydef = qb.and( qb.valueConstraint("jobName", jobName), qb.collection(COLLECTION_JOB_INSTANCE) ); queryMgr.setPageLength((long) count); SearchHandle results = queryMgr.search(querydef, new SearchHandle(), start); MatchDocumentSummary[] summaries = results.getMatchResults(); for (MatchDocumentSummary summary : summaries ) { JAXBHandle<MarkLogicJobInstance> jaxbHandle = new JAXBHandle<>(jaxbContext()); summary.getFirstSnippet(jaxbHandle); MarkLogicJobInstance mji = jaxbHandle.get(); jobInstances.add(mji.getJobInstance()); } return jobInstances; }
@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; } }
StructuredQueryDefinition query = new StructuredQueryBuilder().and(); query.setCollections(qhbTestCollection); QueryBatcher queryBatcher = moveMgr.newQueryBatcher(query)
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; }
StructuredQueryDefinition qd = qb.and(qb.term("woof")); docMgr.setNonDocumentFormat(Format.JSON);
DOMHandle results = new DOMHandle(); StructuredQueryBuilder qb = new StructuredQueryBuilder(); StructuredQueryDefinition qd = qb.and(qb.term("much", "thought")); Transaction t = client.openTransaction(); try {
@Test public void testTestStructuredSearchGeoBox() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException, TransformerException { System.out.println("Running testTestStructuredSearchGeoBox"); String queryOptionName = "geoConstraintOpt.xml"; DatabaseClient client = getDatabaseClient("rest-admin", "x", getConnType()); // write docs loadGeoData(); setQueryOption(client, queryOptionName); QueryManager queryMgr = client.newQueryManager(); // create query def StructuredQueryBuilder qb = queryMgr.newStructuredQueryBuilder(queryOptionName); StructuredQueryDefinition geoElementConstraintQuery = qb.geospatialConstraint("geo-elem-child", qb.box(-12, -5, -11, -4)); StructuredQueryDefinition termQuery = qb.term("karl_kara"); StructuredQueryDefinition finalAndQuery = qb.and(geoElementConstraintQuery, termQuery); // create handle DOMHandle resultsHandle = new DOMHandle(); queryMgr.search(finalAndQuery, resultsHandle); // get the result Document resultDoc = resultsHandle.get(); System.out.println("Output : " + convertXMLDocumentToString(resultDoc)); assertXpathEvaluatesTo("1", "string(//*[local-name()='result'][last()]//@*[local-name()='index'])", resultDoc); assertXpathEvaluatesTo("/geo-constraint/geo-constraint2.xml", "string(//*[local-name()='result']//@*[local-name()='uri'])", resultDoc); // release client client.release(); }
StructuredQueryDefinition termQuery = qb.term("Memex"); StructuredQueryDefinition docQuery = qb.or(qb.document("/dir1/dir2/constraint2.xml"), qb.document("/dir3/dir4/constraint4.xml"), qb.document("/dir3/dir4/constraint5.xml")); StructuredQueryDefinition andFinalQuery = qb.and(termQuery, docQuery);
StructuredQueryDefinition termQuery = qb.term("Memex"); StructuredQueryDefinition dirQuery = qb.directory(true, "/dir3/"); StructuredQueryDefinition andFinalQuery = qb.and(termQuery, dirQuery);
StructuredQueryDefinition termQuery = qb.term("Memex"); StructuredQueryDefinition docQuery = qb.or(qb.document("/dir1/dir2/constraint2.xml"), qb.document("/dir3/dir4/constraint4.xml"), qb.document("/dir3/dir4/constraint5.xml")); StructuredQueryDefinition andFinalQuery = qb.and(termQuery, docQuery);
StructuredQueryDefinition termQuery = qb.term("Memex"); StructuredQueryDefinition docQuery = qb.or(qb.document("/dir1/dir2/constraint2.xml"), qb.document("/dir3/dir4/constraint4.xml"), qb.document("/dir3/dir4/constraint5.xml")); StructuredQueryDefinition andFinalQuery = qb.and(termQuery, docQuery);
@Test public void testBulkSearchSQDwithResponseFormatandStringHandle() throws KeyManagementException, NoSuchAlgorithmException, Exception { loadJSONDocuments(); JSONDocumentManager docMgr = client.newJSONDocumentManager(); QueryManager queryMgr = client.newQueryManager(); StructuredQueryBuilder qb = new StructuredQueryBuilder(); StructuredQueryDefinition qd = qb.and(qb.term("dog1", "dog11")); queryMgr.search(qd, new SearchHandle()); docMgr.setNonDocumentFormat(Format.JSON); docMgr.setSearchView(QueryView.METADATA); docMgr.setMetadataCategories(Metadata.PERMISSIONS); StringHandle results = new StringHandle().withFormat(Format.JSON); DocumentPage page = docMgr.search(qd, 1, results); DocumentMetadataHandle mh = new DocumentMetadataHandle(); while (page.hasNext()) { DocumentRecord rec = page.next(); validateRecord(rec, Format.JSON); docMgr.readMetadata(rec.getUri(), mh); assertTrue("Records has permissions? ", mh.getPermissions().containsKey("flexrep-eval")); assertTrue("Record has collections ?", mh.getCollections().isEmpty()); } assertFalse("Search handle contains", results.get().isEmpty()); }
StructuredQueryDefinition termQuery = qb.term("Memex"); StructuredQueryDefinition collQuery = qb.or(qb.collection("http://test.com/set1"), qb.collection("http://test.com/set3")); StructuredQueryDefinition andFinalQuery = qb.and(termQuery, collQuery);
StructuredQueryDefinition qd = qb.and(qb.term("foo", "bar"));