if ( structuredQuery != null ) structure = structuredQuery.serialize(); if ( rawQuery != null ) structure = HandleAccessor.contentAsString(rawQuery.getHandle()); out.write(structure.getBytes("UTF-8"));
structure = ((StructuredQueryDefinition) queryDef).serialize();
.accept("application/xml"); } else if (queryDef instanceof StructuredQueryDefinition) { structure = ((StructuredQueryDefinition) queryDef).serialize();
structure = ((StructuredQueryDefinition) queryDef).serialize();
@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; }
return postResource(reqlog, "internal/uris", transaction, params, input, output); } else if (qdef instanceof StructuredQueryDefinition) { String structure = ((StructuredQueryDefinition) qdef).serialize();
.accept(mimetype); } else if (queryDef instanceof StructuredQueryDefinition) { structure = ((StructuredQueryDefinition) queryDef).serialize();
.serialize(); if (structure != null) { addEncodedParam(docParams, "structuredQuery", structure);
@Test public void testConvertedSearches() throws IOException { // Structured Query, No Options StructuredQueryBuilder qb = queryMgr.newStructuredQueryBuilder(null); StructuredQueryDefinition t = qb.term("leaf3"); check(new StringHandle(head + t.serialize() + returnQueryOption + tail)); // String query no options String str = head + qtext1 + returnQueryOption + tail; check(new StringHandle(str).withMimetype("application/xml")); // String query plus options str = head + qtext2 + optionsString + tail; check(new StringHandle(str)); // Structured query plus options str = head + t.serialize() + optionsString + tail; check(new StringHandle(str)); // Structured query plus options str = head + t.serialize() + optionsString + tail; check(new StringHandle(str), "alerts"); // All three str = head + qtext3 + t.serialize() + optionsString + tail; check(new StringHandle(str)); }
@Test public void testCombinedSearches() throws IOException { // Structured Query, No Options StructuredQueryBuilder qb = queryMgr.newStructuredQueryBuilder(null); StructuredQueryDefinition t = qb.term("leaf3"); check(new StringHandle(head + t.serialize() + tail)); // String query no options String str = head + qtext1 + tail; check(new StringHandle(str).withMimetype("application/xml")); // String query plus options str = head + qtext2 + optionsString + tail; check(new StringHandle(str)); // Structured query plus options str = head + t.serialize() + optionsString + tail; check(new StringHandle(str)); // Structured query plus options str = head + t.serialize() + optionsString + tail; check(new StringHandle(str), "alerts"); // All three str = head + qtext3 + t.serialize() + optionsString + tail; check(new StringHandle(str)); }
.serialize(); if (structure != null) { docParams.add("structuredQuery", structure);
for (String q: new String[]{t.serialize(), qb.build(t).toString()}) { xml = new StringInputStream(q); parser.parse(xml, handler); for (String q: new String[]{u.serialize(), qb.build(u).toString()}) { xml = new StringInputStream(q); parser.parse(xml, handler); for (String q: new String[]{v.serialize(), qb.build(v).toString()}) { xml = new StringInputStream(q); parser.parse(xml, handler); for (String q: new String[]{t.serialize(), qb.build(t).toString()}) { xml = new StringInputStream(q); parser.parse(xml, handler); for (String q: new String[]{t.serialize(), qb.build(t).toString()}) { xml = new StringInputStream(q); parser.parse(xml, handler); for (String q: new String[]{t.serialize(), qb.build(t).toString()}) { xml = new StringInputStream(q); parser.parse(xml, handler); for (String q: new String[]{t.serialize(), qb.build(t).toString()}) { xml = new StringInputStream(q); parser.parse(xml, handler); for (String q: new String[]{t.serialize(), qb.build(t).toString()}) {
String structuredString = qb.valueConstraint("name", "one").serialize();
@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()); } }
@Test public void testFailedSearch() throws IOException { StructuredQueryBuilder qb = queryMgr.newStructuredQueryBuilder(); StructuredQueryDefinition t = qb.term("criteriaThatShouldNotMatchAnyDocument"); RawCombinedQueryDefinition queryDef = queryMgr.newRawCombinedQueryDefinition( new StringHandle(head + t.serialize() + tail) .withMimetype("application/xml") ); SearchHandle results = queryMgr.search(queryDef, new SearchHandle()); assertNotNull(results); MatchDocumentSummary[] summaries = results.getMatchResults(); assertTrue(summaries == null || summaries.length == 0); StringHandle criteria = new StringHandle().withFormat(Format.XML); criteria.set("<q:query xmlns:q='" + RawQueryByExampleDefinition.QBE_NS + "'>" + "<q:word>criteriaThatShouldNotMatchAnyDocument</q:word>" + "</q:query>"); RawQueryByExampleDefinition qbe = queryMgr.newRawQueryByExampleDefinition(criteria); results = queryMgr.search(qbe, new SearchHandle()); assertNotNull(results); summaries = results.getMatchResults(); assertTrue(summaries == null || summaries.length == 0); }