@Test public void testXMLDocsAsSearchOptions() throws ParserConfigurationException, SAXException, IOException, ResourceNotFoundException, ForbiddenUserException, FailedRequestException, ResourceNotResendableException { String optionsName = "invalid"; Document domDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Element root = domDocument.createElementNS("http://marklogic.com/appservices/search","options"); Element rf = domDocument.createElementNS("http://marklogic.com/appservices/search","return-facets"); rf.setTextContent("true"); root.appendChild(rf); root.setAttributeNS("http://www.w3.org/XML/1998/namespace", "lang", "en"); // MarkLogic adds this if I don't domDocument.appendChild(root); QueryOptionsManager queryOptionsMgr = Common.adminClient.newServerConfigManager().newQueryOptionsManager(); queryOptionsMgr.writeOptions(optionsName, new DOMHandle(domDocument)); String domString = ((DOMImplementationLS) DocumentBuilderFactory.newInstance().newDocumentBuilder() .getDOMImplementation()).createLSSerializer().writeToString(domDocument); String optionsString = queryOptionsMgr.readOptions(optionsName, new StringHandle()).get(); assertNotNull("Read null string for XML content",optionsString); logger.debug("Two XML Strings {} and {}", domString, optionsString); Document readDoc = queryOptionsMgr.readOptions(optionsName, new DOMHandle()).get(); assertNotNull("Read null document for XML content",readDoc); }
@Test public void testJSONOptions() throws JAXBException, ResourceNotFoundException, ForbiddenUserException, FailedRequestException, ResourceNotResendableException { QueryOptionsManager mgr = Common.adminClient.newServerConfigManager().newQueryOptionsManager(); assertNotNull("Client could not create query options manager", mgr); FileHandle jsonHandle = new FileHandle(new File("src/test/resources/json-config.json")); jsonHandle.setFormat(Format.JSON); mgr.writeOptions("jsonoptions", jsonHandle); JsonNode options = mgr.readOptions("jsonoptions", new JacksonHandle()).get(); assertEquals("JSON options came back incorrectly", options.findPath("constraint").get(0).get("name").textValue(), "decade"); StringHandle jsonStringHandle = new StringHandle(); jsonStringHandle.setFormat(Format.JSON); mgr.readOptions("jsonoptions", jsonStringHandle); assertTrue("JSON String from QueryManager must start with json options", jsonStringHandle.get().startsWith("{\"options\":")); mgr.deleteOptions("jsonoptions"); }; }
@Test public void testJSONConverter() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException, TransformerException { System.out.println("Running testJSONConverter"); // String queryOptionName = "jsonConverterOpt.json"; String queryOptionName = "queryValidationOpt.json"; DatabaseClient client = getDatabaseClient("rest-admin", "x", getConnType()); // create a manager for writing query options QueryOptionsManager optionsMgr = client.newServerConfigManager().newQueryOptionsManager(); // create handle FileHandle handle = new FileHandle(new File("src/test/java/com/marklogic/client/functionaltest/queryoptions/" + queryOptionName)); handle.setFormat(Format.JSON); // write the query options to the database optionsMgr.writeOptions(queryOptionName, handle); System.out.println("Write " + queryOptionName + " to database"); // read query option with QueryOptionsHandle StringHandle readHandle = new StringHandle(); optionsMgr.readOptions(queryOptionName, readHandle); String output = readHandle.toString(); System.out.println(output); System.out.println("============================"); client.release(); }
@Test public void testBug19092() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException, TransformerException { System.out.println("Running testBug19092"); DatabaseClient client = getDatabaseClient("rest-admin", "x", getConnType()); // create query options manager QueryOptionsManager optionsMgr = client.newServerConfigManager().newQueryOptionsManager(); // create query options handle String xmlOptions = "<search:options xmlns:search='http://marklogic.com/appservices/search'>" + "<search:term>" + "<search:term-option>case-sensitive</search:term-option>" + "</search:term>" + "</search:options>"; StringHandle handle = new StringHandle(xmlOptions); // write query options optionsMgr.writeOptions("DefaultTermOpt", handle); // read query option StringHandle readHandle = new StringHandle(); readHandle.setFormat(Format.XML); optionsMgr.readOptions("DefaultTermOpt", readHandle); String output = readHandle.get(); System.out.println(output); assertTrue("Default term is not correct", output.contains("<ns2:term-option>case-sensitive</ns2:term-option>") || output.contains("<search:term-option>case-sensitive</search:term-option>")); assertFalse("Weight element exists", output.contains("<ns2:weight>0.0</ns2:weight>") || output.contains("<search:weight>0.0</search:weight>")); assertFalse("Default element exists", output.contains("<ns2:default/>") || output.contains("<search:default/>")); // release client client.release(); }
@Test public void testQueryOptionsManager() throws JAXBException, ResourceNotFoundException, ForbiddenUserException, FailedRequestException, ResourceNotResendableException { QueryOptionsManager mgr = Common.adminClient.newServerConfigManager().newQueryOptionsManager(); assertNotNull("Client could not create query options manager", mgr); mgr.writeOptions("testempty", new StringHandle("{\"options\":{}}").withFormat(Format.JSON)); String optionsResult = mgr.readOptions("testempty", new StringHandle()).get(); logger.debug("Empty options from server {}", optionsResult); assertTrue("Empty options result not empty",optionsResult.contains("options")); assertTrue("Empty options result not empty",optionsResult.contains("\"http://marklogic.com/appservices/search\"/>")); mgr.deleteOptions("testempty"); };
optionsMgr.readOptions(queryOptionName, readHandle);
@Test public void testBug19140() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException, TransformerException { System.out.println("Running testBug19140"); DatabaseClient client = getDatabaseClient("rest-admin", "x", getConnType()); // create query options manager QueryOptionsManager optionsMgr = client.newServerConfigManager().newQueryOptionsManager(); // create query options handle String xmlOptions = "<search:options xmlns:search='http://marklogic.com/appservices/search'>" + "<search:transform-results apply='raw'/>" + "</search:options>"; StringHandle handle = new StringHandle(xmlOptions); // write query options optionsMgr.writeOptions("RawResultsOpt", handle); // read query option StringHandle readHandle = new StringHandle(); readHandle.setFormat(Format.XML); optionsMgr.readOptions("RawResultsOpt", readHandle); String output = readHandle.get(); System.out.println(output); assertTrue("transform-results is incorrect", output.contains("transform-results apply=\"raw\"/")); assertFalse("preferred-elements is exist", output.contains("preferred-elements/")); // release client client.release(); }
optionsMgr.readOptions(queryOptionName, readHandle); String output = readHandle.toString(); System.out.println(output); optionsMgr.readOptions(queryOptionNamePOJO, readHandle); String outputPOJO = readHandle.toString(); System.out.println(outputPOJO);
@Test public void testBug19092WithJson() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException, TransformerException { System.out.println("Running testBug19092WithJson"); DatabaseClient client = getDatabaseClient("rest-admin", "x", getConnType()); // create query options manager QueryOptionsManager optionsMgr = client.newServerConfigManager().newQueryOptionsManager(); // create query options handle String xmlOptions = "<search:options xmlns:search='http://marklogic.com/appservices/search'>" + "<search:term>" + "<search:term-option>case-sensitive</search:term-option>" + "</search:term>" + "</search:options>"; StringHandle handle = new StringHandle(xmlOptions); // write query options optionsMgr.writeOptions("DefaultTermOpt", handle); // read query option StringHandle readHandle = new StringHandle(); readHandle.setFormat(Format.JSON); optionsMgr.readOptions("DefaultTermOpt", readHandle); String output = readHandle.get(); System.out.println(output); assertTrue("Default term is not correct", output.contains("{\"options\":{\"term\":{\"term-option\":[\"case-sensitive\"]}}}")); // release client client.release(); }
optionsMgr.readOptions("FacetValueOpt", readHandle); String output = readHandle.get(); System.out.println(output);
optionsMgr.readOptions(queryOptionName, readHandle); String output = readHandle.toString(); System.out.println(output); optionsMgr.readOptions(queryOptionNamePOJO, readHandle); String outputPOJO = readHandle.toString(); System.out.println(outputPOJO);
optionsMgr.readOptions(queryOptionName, readHandle); String output = readHandle.toString(); optionsMgr.readOptions(queryOptionNamePOJO, readHandle); String outputPOJO = readHandle.toString();
optionsMgr.readOptions("SearchableExpressionDescendantOrSelf", readHandle); String output = readHandle.get(); System.out.println(output);
optionsMgr.readOptions("SearchableExpressionFunction", readHandle); String output = readHandle.get(); System.out.println(output);
optionsMgr.readOptions("SearchableExpressionChildAxis", readHandle); String output = readHandle.get(); System.out.println(output);
optionsMgr.readOptions("SearchableExpressionDescendantAxis", readHandle); String output = readHandle.get(); System.out.println(output);
optionsMgr.readOptions("SearchableExpressionOrOperator", readHandle); String output = readHandle.get(); System.out.println(output);
optionsMgr.readOptions("WordConstraintNormalWordQuery", readHandle); String output = readHandle.get(); System.out.println(output);
optionsMgr.readOptions("SortOrderDescendingScore", readHandle); String output = readHandle.get(); System.out.println(output);
optionsMgr.readOptions("ExtractMetadataWithStructuredSearch", readHandle); String output = readHandle.get(); System.out.println(output);