RawCtsQueryDefinition querydef = queryMgr.newRawCtsQueryDefinition(handle, queryOptionName);
@Test public void testRawCtsQueryFromFileHandle() throws Exception { Common.client.newDocumentManager().write("testRawCtsQueryFromFileHandle.xml", new FileHandle(new File("src/test/resources/constraint5.xml")).withFormat(Format.XML)); String ctsQueryFilePath = "ctsQuery1.xml"; String ctsQueryAsString = Common.testFileToString(ctsQueryFilePath); File ctsQueryFile = new File(Common.getResourceUri(ctsQueryFilePath)); FileHandle ctsHandle = new FileHandle(ctsQueryFile); QueryDefinition[] queries = new QueryDefinition[] { queryMgr.newRawCombinedQueryDefinition(ctsHandle), queryMgr.newRawCtsQueryDefinition(ctsHandle), queryMgr.newRawCombinedQueryDefinitionAs(Format.XML, ctsQueryFile), queryMgr.newRawCtsQueryDefinitionAs(Format.XML, ctsQueryFile), queryMgr.newRawCtsQueryDefinition(new InputStreamHandle(new FileInputStream(ctsQueryFile))), queryMgr.newRawCtsQueryDefinition(new StringHandle(ctsQueryAsString)), queryMgr.newRawCtsQueryDefinition(new DOMHandle(Common.testStringToDocument(ctsQueryAsString))) }; for ( QueryDefinition query : queries ) { // create result handle DOMHandle resultsHandle = new DOMHandle(); queryMgr.search(query, resultsHandle); // get the result Document resultDoc = resultsHandle.get(); assertXpathEvaluatesTo("1", "string(//*[local-name()='result'][last()]//@*[local-name()='index'])", resultDoc); assertXpathEvaluatesTo("0026", "string(//*[local-name()='result'][1]//*[local-name()='id' or local-name()='highlight'])", resultDoc); } }
"<cts:text>groundbreaking</cts:text></cts:word-query>"; StringHandle handle = new StringHandle().with(wordQuery); RawCtsQueryDefinition querydef = queryMgr.newRawCtsQueryDefinition(handle);
@Test public void testRawCtsQuery() throws Exception { String ctsQuery = "<cts:directory-query xmlns:cts=\"http://marklogic.com/cts\"><cts:uri>/QueryBatcherTest/</cts:uri></cts:directory-query>"; RawCtsQueryDefinition query = client.newQueryManager().newRawCtsQueryDefinition(new StringHandle().with(ctsQuery).withFormat(Format.XML)).withCriteria("Jane"); Map<String, String[]> matchesByForest = new HashMap<>(); matchesByForest.put("java-unittest-3", new String[] {uri2}); runQueryBatcher(moveMgr.newQueryBatcher(query), query, matchesByForest, 1, 2); ctsQuery = "{ctsquery : {\"directoryQuery\":{\"uris\":[\"/QueryBatcherTest/\"]}}}";; matchesByForest.put("java-unittest-1", new String[] {uri1, uri3, uri4}); matchesByForest.put("java-unittest-2", new String[] {uri5}); query = client.newQueryManager().newRawCtsQueryDefinition(new StringHandle().with(ctsQuery).withFormat(Format.JSON)); runQueryBatcher(moveMgr.newQueryBatcher(query), query, matchesByForest, 1, 2); }
"<cts:text>groundbreaking</cts:text></cts:word-query>"; StringHandle handle = new StringHandle().with(wordQuery); RawCtsQueryDefinition querydef = queryMgr.newRawCtsQueryDefinition(handle).withCriteria("Memex"); RawCtsQueryDefinition querydef2 = queryMgr.newRawCtsQueryDefinition(handle); querydef2.setHandle(handle2.withFormat(Format.JSON)); queryMgr.search(querydef2, jacksonHandle2);
@Test public void testRawCombinedCtsQueryFromFileHandle() throws Exception { Common.client.newDocumentManager().write("testRawCtsQueryFromFileHandle.xml", new FileHandle(new File("src/test/resources/constraint5.xml")).withFormat(Format.XML)); FileHandle ctsHandle = new FileHandle(new File("src/test/resources/combinedCtsQuery.xml")); QueryDefinition[] queries = new QueryDefinition[] { queryMgr.newRawCombinedQueryDefinition(ctsHandle), queryMgr.newRawCtsQueryDefinition(ctsHandle), }; for ( QueryDefinition query : queries ) { // create result handle DOMHandle resultsHandle = new DOMHandle(); queryMgr.search(query, resultsHandle); // get the result Document resultDoc = resultsHandle.get(); assertXpathEvaluatesTo("1", "string(//*[local-name()='result'][last()]//@*[local-name()='index'])", resultDoc); assertXpathEvaluatesTo("0026", "string(//*[local-name()='result'][1]//*[local-name()='id' or local-name()='highlight'])", resultDoc); } } }
StringHandle handle = new StringHandle().with(wordQuery).withFormat(Format.XML); RawCtsQueryDefinition queryRawDef = queryMgr.newRawCtsQueryDefinition(handle);
StringHandle handle = new StringHandle().with(wordQuery).withFormat(Format.XML); RawCtsQueryDefinition queryRawDef = queryMgr.newRawCtsQueryDefinition(handle); valuesDef.setQueryDefinition(queryRawDef);
private void checkCts(CtsQueryWriteHandle handle, String optionsName, long numMatches) { RawCtsQueryDefinition rawCtsQueryDefinition; if (optionsName == null) { rawCtsQueryDefinition = queryMgr.newRawCtsQueryDefinition(handle); } else { rawCtsQueryDefinition = queryMgr.newRawCtsQueryDefinition(handle, optionsName); } SearchHandle results; results = queryMgr.search(rawCtsQueryDefinition, new SearchHandle()); assertNotNull(results); assertEquals(results.getTotalResults(), numMatches); assertFalse(results.getMetrics().getTotalTime() == -1); MatchDocumentSummary[] summaries = results.getMatchResults(); assertNotNull(summaries); assertTrue(summaries.length > 0); for (MatchDocumentSummary summary : summaries) { assertTrue("Mime type of document", summary.getMimeType().matches("(application|text)/xml")); assertEquals("Format of document", Format.XML, summary.getFormat()); MatchLocation[] locations = summary.getMatchLocations(); for (MatchLocation location : locations) { assertNotNull(location.getAllSnippetText()); } } }
"<cts:text>NoSQL</cts:text></cts:word-query>"; StringHandle handle = new StringHandle().with(wordQuery); RawCtsQueryDefinition querydef = queryMgr.newRawCtsQueryDefinition(handle); RawCtsQueryDefinition qdefWithTransform = queryMgr.newRawCtsQueryDefinition(handle); ServerTransform transformOnQdef = new ServerTransform("add-attr-xquery-transform"); transformOnQdef.put("name", "Continent"); transform2.put("value", "Earth"); RawCtsQueryDefinition qdefWithTransform2 = queryMgr.newRawCtsQueryDefinition(handle); qdefWithTransform2.setResponseTransform(transform2); DocumentPage pageAddElement = docMgrSrch.search(qdefWithTransform2, 1);
break; case 2: RawCtsQueryDefinition query = queryMgr.newRawCtsQueryDefinition(null); query.setCriteria("10"); vQuery = query; String ctsQuery = "<word-query xmlns=\"http://marklogic.com/cts\"><text>10</text></word-query>"; StringHandle handle = new StringHandle(ctsQuery).withFormat(Format.XML); RawCtsQueryDefinition rawCtsQuery = queryMgr.newRawCtsQueryDefinition(handle); vQuery = rawCtsQuery; break;