本文整理了Java中com.marklogic.client.query.QueryManager.newStringDefinition
方法的一些代码示例,展示了QueryManager.newStringDefinition
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。QueryManager.newStringDefinition
方法的具体详情如下:
包路径:com.marklogic.client.query.QueryManager
类名称:QueryManager
方法名:newStringDefinition
[英]Creates a query definition based on a string and the default query options. The string has a simple grammar for specifying constraint values for indexes and can be supplied by an end-user in a web form.
[中]基于字符串和默认查询选项创建查询定义。该字符串有一个简单的语法,用于指定索引的约束值,最终用户可以以web形式提供该字符串。
代码示例来源:origin: com.marklogic/ml-javaclient-util
public List<String> getUrisInCollection(String collectionName, int pageLength) {
QueryManager mgr = getClient().newQueryManager();
mgr.setPageLength(pageLength);
StringQueryDefinition def = mgr.newStringDefinition();
def.setCollections(collectionName);
SearchHandle h = mgr.search(def, new SearchHandle());
List<String> uris = new ArrayList<String>();
for (MatchDocumentSummary s : h.getMatchResults()) {
uris.add(s.getUri());
}
return uris;
}
代码示例来源:origin: com.marklogic/ml-javaclient-util
public long getCollectionSize(String collectionName) {
QueryManager queryMgr = getClient().newQueryManager();
StringQueryDefinition def = queryMgr.newStringDefinition();
def.setCollections(collectionName);
SearchHandle sh = queryMgr.search(def, new SearchHandle());
return sh.getTotalResults();
}
代码示例来源:origin: com.marklogic/marklogic-spring-batch
@Override
public List<JobInstance> getJobInstances(String jobName, int start, int count) {
QueryManager queryMgr = databaseClient.newQueryManager();
StringQueryDefinition querydef = queryMgr.newStringDefinition(SEARCH_OPTIONS_NAME);
querydef.setCriteria("jobName: " + jobName + " AND sort:date");
logger.info(querydef.getCriteria());
SearchHandle results = queryMgr.search(querydef, new SearchHandle());
List<JobInstance> jobInstances = new ArrayList<>();
MatchDocumentSummary[] summaries = results.getMatchResults();
MarkLogicJobInstance mji;
if (start+count > summaries.length) {
return jobInstances;
}
for (int i = start; i < start+count; i++) {
JAXBHandle<MarkLogicJobInstance> jaxbHandle = new JAXBHandle<>(jaxbContext());
summaries[i].getFirstSnippet(jaxbHandle);
mji = jaxbHandle.get();
jobInstances.add(mji.getJobInstance());
}
return jobInstances;
}
代码示例来源:origin: marklogic/java-client-api
@Test
public void testStringQuery() throws Exception {
StringQueryDefinition query = client.newQueryManager().newStringDefinition().withCriteria("John AND dept:HR");
query.setCollections(qhbTestCollection);
query.setOptionsName("employees");
Map<String, String[]> matchesByForest = new HashMap<>();
matchesByForest.put("java-unittest-1", new String[] {uri1, uri3, uri4});
matchesByForest.put("java-unittest-2", new String[] {});
matchesByForest.put("java-unittest-3", new String[] {});
runQueryBatcher(moveMgr.newQueryBatcher(query), query, matchesByForest, 99, 17);
}
代码示例来源:origin: marklogic/java-client-api
public SearchHandle runSearch(DatabaseClient client, String queryOptionName, String criteria)
{
// create a manager for searching
QueryManager queryMgr = client.newQueryManager();
// create a search definition
StringQueryDefinition querydef = queryMgr.newStringDefinition(queryOptionName);
querydef.setCriteria(criteria);
// create a handle for the search results
SearchHandle resultsHandle = new SearchHandle();
// run the search
return queryMgr.search(querydef, resultsHandle);
}
代码示例来源:origin: marklogic/java-client-api
@Test
public void testFacetSearch()
throws IOException, ParserConfigurationException, SAXException, FailedRequestException, ForbiddenUserException,
ResourceNotFoundException, ResourceNotResendableException
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(false);
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new InputSource(new StringReader(options)));
mgr = Common.adminClient.newServerConfigManager().newQueryOptionsManager();
mgr.writeOptions("photos", new DOMHandle(document));
QueryManager queryMgr = Common.client.newQueryManager();
StringQueryDefinition qdef = queryMgr.newStringDefinition("photos");
qdef.setCriteria("Grand");
SearchHandle results = queryMgr.search(qdef, new SearchHandle());
assertNotNull(results);
FacetResult[] facets = results.getFacetResults();
assertNotNull(facets);
}
代码示例来源:origin: marklogic/java-client-api
@Test
public void testSearchLog() {
QueryManager qMgr = Common.client.newQueryManager();
ByteArrayOutputStream out = null;
RequestLogger logger = null;
String outString = null;
out = new ByteArrayOutputStream();
logger = Common.client.newLogger(out);
logger.setContentMax(RequestLogger.ALL_CONTENT);
qMgr.startLogging(logger);
QueryDefinition querydef = qMgr.newStringDefinition();
qMgr.search(querydef, new SearchHandle());
outString = new String(out.toByteArray());
assertTrue("Search failed to log output", outString != null && outString.length() > 0);
out = new ByteArrayOutputStream();
logger = Common.client.newLogger(out);
logger.setContentMax(RequestLogger.ALL_CONTENT);
qMgr.startLogging(logger);
DeleteQueryDefinition deleteDef = qMgr.newDeleteDefinition();
deleteDef.setCollections("x");
qMgr.delete(deleteDef);
outString = new String(out.toByteArray());
assertTrue("SearchDelete failed to log output", outString != null && outString.length() > 0);
}
代码示例来源:origin: marklogic/java-client-api
@Test
public void testBug19016() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException
{
System.out.println("Running testBug19016");
String[] filenames = { "bug19016.xml" };
DatabaseClient client = getDatabaseClient("rest-admin", "x", getConnType());
// write docs
for (String filename : filenames)
{
writeDocumentUsingInputStreamHandle(client, filename, "/bug19016/", "XML");
}
QueryManager queryMgr = client.newQueryManager();
// create query def
StringQueryDefinition querydef = queryMgr.newStringDefinition();
querydef.setCriteria("this\"is\"an%33odd string");
String result = queryMgr.search(querydef, new StringHandle()).get();
System.out.println(result);
assertTrue("qtext is not correct", result.contains("<search:qtext>this\"is\"an%33odd string</search:qtext>"));
// release client
client.release();
}
代码示例来源:origin: marklogic/java-client-api
@Test
public void testPOJORepoSearchWithUTF8NoTransaction() {
PojoRepository<SpecialArtifact, String> pojoReposProductsString = client.newPojoRepository(SpecialArtifact.class, String.class);
SpecialArtifact searchSpArtifact = null;
// Load the object into database
long longId = getOneNegativeLongId();
String artifactName = new String("万里长城" + longId);
pojoReposProductsString.write(this.setSpecialArtifactWithSpecialCharacter(longId, artifactName), "odd", "numbers");
assertTrue(pojoReposProductsString.exists(artifactName));
// Validate the artifact search.
StringQueryDefinition query = client.newQueryManager().newStringDefinition();
query.setCriteria(artifactName);
PojoPage<SpecialArtifact> pojoSpecialArtifactPage = pojoReposProductsString.search(query, 1);
Iterator<SpecialArtifact> iter = pojoSpecialArtifactPage.iterator();
while (iter.hasNext()) {
searchSpArtifact = iter.next();
validateSpecialArtifactWithSpecialCharacter(searchSpArtifact, artifactName, longId);
}
}
代码示例来源:origin: marklogic/java-client-api
@Test
public void testJSON()
throws FailedRequestException, ForbiddenUserException, ResourceNotFoundException, ResourceNotResendableException
{
String optionsName = writeOptions();
QueryManager queryMgr = Common.client.newQueryManager();
StringQueryDefinition qdef = queryMgr.newStringDefinition(optionsName);
qdef.setCriteria("grandchild1 OR grandchild4");
qdef.setDirectory("/sample/");
queryMgr.setView(QueryView.FACETS);
// create a handle for the search results
StringHandle resultsHandle = new StringHandle().withFormat(Format.JSON);
// run the search
queryMgr.search(qdef, resultsHandle);
assertEquals("{", resultsHandle.get().substring(0, 1)); // It's JSON, right?
}
代码示例来源:origin: marklogic/java-client-api
@Test
public void testBulkSearchSQDwithNoResults() throws KeyManagementException, NoSuchAlgorithmException, Exception {
loadTxtDocuments();
TextDocumentManager docMgr = client.newTextDocumentManager();
QueryManager queryMgr = client.newQueryManager();
StringQueryDefinition qd = queryMgr.newStringDefinition();
qd.setCriteria("zzzz");
SearchHandle results = new SearchHandle();
DocumentPage page = docMgr.search(qd, 1, results);
assertFalse("Should return no results", page.hasNext());
}
代码示例来源:origin: marklogic/java-client-api
@Test(expected = UnsupportedOperationException.class)
public void testBulkSearchSQDwithWrongResponseFormat() throws KeyManagementException, NoSuchAlgorithmException, Exception {
loadTxtDocuments();
TextDocumentManager docMgr = client.newTextDocumentManager();
QueryManager queryMgr = client.newQueryManager();
StringQueryDefinition qd = queryMgr.newStringDefinition();
qd.setCriteria("bar");
docMgr.setNonDocumentFormat(Format.JSON);
SearchHandle results = new SearchHandle();
DocumentPage page = docMgr.search(qd, 1, results);
MatchDocumentSummary[] summaries = results.getMatchResults();
for (MatchDocumentSummary summary : summaries) {
MatchLocation[] locations = summary.getMatchLocations();
for (MatchLocation location : locations) {
System.out.println(location.getAllSnippetText());
// do something with the snippet text
}
}
}
代码示例来源:origin: marklogic/java-client-api
@Test
public void testFailedSearch() throws IOException {
QueryManager queryMgr = Common.client.newQueryManager();
queryMgr.setView(QueryView.RESULTS);
StringQueryDefinition qdef = queryMgr.newStringDefinition();
qdef.setCriteria("criteriaThatShouldNotMatchAnyDocument");
qdef.setDirectory("/sample/");
SearchHandle results = queryMgr.search(qdef, new SearchHandle());
assertNotNull(results);
MatchDocumentSummary[] summaries = results.getMatchResults();
assertTrue(summaries == null || summaries.length == 0);
}
代码示例来源:origin: marklogic/java-client-api
@Test
public void testH_DeletePojos() throws Exception {
cities.delete(1185098, 2239076);
StringQueryDefinition query = Common.client.newQueryManager().newStringDefinition();
query.setCriteria("Tungi OR Dalatando OR Chittagong");
try ( PojoPage<City> page = cities.search(query, 1) ) {
assertEquals("Failed to read number of records expected", 1, page.getTotalSize());
}
// now delete them all
cities.deleteAll();
long count = cities.count();
assertEquals("Failed to read number of records expected", 0, count);
}
代码示例来源:origin: marklogic/java-client-api
static public void cleanUp() {
DatabaseClient client = DatabaseClientFactory.newClient(Common.HOST, Common.PORT, new DigestAuthContext(Common.SERVER_ADMIN_USER, Common.SERVER_ADMIN_PASS));
try {
QueryManager queryMgr = client.newQueryManager();
queryMgr.setPageLength(1000);
QueryDefinition query = queryMgr.newStringDefinition();
query.setCollections(temporalCollection);
// DeleteQueryDefinition deleteQuery = client.newQueryManager().newDeleteDefinition();
// deleteQuery.setCollections(temporalCollection);
// client.newQueryManager().delete(deleteQuery);
SearchHandle handle = queryMgr.search(query, new SearchHandle());
MatchDocumentSummary[] docs = handle.getMatchResults();
for ( MatchDocumentSummary doc : docs ) {
if ( ! (temporalCollection + ".lsqt").equals(doc.getUri()) ) {
client.newXMLDocumentManager().delete(doc.getUri());
}
}
} finally {
client.release();
}
}
}
代码示例来源:origin: marklogic/java-client-api
@Test
public void testPointPositiveLangLat() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException,
TransformerException
{
System.out.println("Running testPointPositiveLangLat");
String queryOptionName = "geoConstraintOpt.xml";
DatabaseClient client = getDatabaseClient("rest-admin", "x", getConnType());
// write docs
loadGeoData();
setQueryOption(client, queryOptionName);
QueryManager queryMgr = client.newQueryManager();
// create query def
StringQueryDefinition querydef = queryMgr.newStringDefinition(queryOptionName);
querydef.setCriteria("geo-elem-pair:\"12,5\"");
// create handle
DOMHandle resultsHandle = new DOMHandle();
queryMgr.search(querydef, resultsHandle);
// get the result
Document resultDoc = resultsHandle.get();
assertXpathEvaluatesTo("1", "string(//*[local-name()='result'][last()]//@*[local-name()='index'])", resultDoc);
assertXpathEvaluatesTo("karl_kara 12,5 12,5 12 5", "string(//*[local-name()='result'][1]//*[local-name()='match'])", resultDoc);
// release client
client.release();
}
代码示例来源:origin: marklogic/java-client-api
@Test
public void testBoxAndWord() throws KeyManagementException, NoSuchAlgorithmException, IOException, ParserConfigurationException, SAXException, XpathException,
TransformerException
{
System.out.println("Running testBoxAndWord");
String queryOptionName = "geoConstraintOpt.xml";
DatabaseClient client = getDatabaseClient("rest-admin", "x", getConnType());
// write docs
loadGeoData();
setQueryOption(client, queryOptionName);
QueryManager queryMgr = client.newQueryManager();
// create query def
StringQueryDefinition querydef = queryMgr.newStringDefinition(queryOptionName);
querydef.setCriteria("geo-elem-pair:\"[-12,4,-11,5]\" AND karl_kara");
// create handle
DOMHandle resultsHandle = new DOMHandle();
queryMgr.search(querydef, resultsHandle);
// get the result
Document resultDoc = resultsHandle.get();
assertXpathEvaluatesTo("1", "string(//*[local-name()='result'][last()]//@*[local-name()='index'])", resultDoc);
assertXpathEvaluatesTo("/geo-constraint/geo-constraint20.xml", "string(//*[local-name()='result']//@*[local-name()='uri'])", resultDoc);
// release client
client.release();
}
代码示例来源:origin: marklogic/java-client-api
@Test
public void testMatchGetQuery() {
StringQueryDefinition qtext = queryManager
.newStringDefinition("alerts");
qtext.setCriteria("favorited:true");
RuleDefinitionList answer = ruleManager.match(qtext,
new RuleDefinitionList());
assertEquals("One answer", 1, answer.size());
qtext.setCriteria("favorited:false");
answer = ruleManager.match(qtext, 1L, 10L, new String[] { "favorites",
"notfavorited" }, answer);
assertEquals("One answer", answer.size(), 1);
assertEquals("Right answer", "notfavorited", answer.iterator().next()
.getName());
answer = ruleManager.match(qtext, 1L, 0L, new String[] { "favorites",
"notfavorited" }, answer);
assertEquals("Zero answers (pageLength 0)", answer.size(), 0);
answer = ruleManager.match(qtext, 3L, QueryManager.DEFAULT_PAGE_LENGTH, new String[] { "favorites",
"notfavorited" }, answer);
assertEquals("Zero answers (default pageLength, but start beyond result size)", answer.size(), 0);
}
代码示例来源:origin: marklogic/java-client-api
@Test
public void testStringSearch2() throws IOException {
QueryManager queryMgr = Common.client.newQueryManager();
StringQueryDefinition qdef = queryMgr.newStringDefinition();
qdef.setCriteria("10");
qdef.setDirectory("/sample/");
SearchHandle handle = new SearchHandle();
handle = queryMgr.search(qdef, handle);
assertNotNull(handle);
MatchDocumentSummary[] summaries = handle.getMatchResults();
assertNotNull(summaries);
assertEquals("expected 2 results", 2, summaries.length);
for ( MatchDocumentSummary summary : summaries ) {
MatchLocation[] locations = summary.getMatchLocations();
assertEquals("expected 1 match location", 1, locations.length);
for ( MatchLocation location : locations ) {
assertNotNull(location.getAllSnippetText());
}
}
}
代码示例来源:origin: marklogic/java-client-api
@Test
public void testStringSearch()
throws IOException, ParserConfigurationException, SAXException, FailedRequestException, ForbiddenUserException,
ResourceNotFoundException, ResourceNotResendableException
{
String optionsName = writeOptions();
QueryManager queryMgr = Common.client.newQueryManager();
StringQueryDefinition qdef = queryMgr.newStringDefinition(optionsName);
qdef.setCriteria("grandchild1 OR grandchild4");
qdef.setDirectory("/sample/");
SearchHandle results = queryMgr.search(qdef, new SearchHandle());
assertNotNull(results);
assertFalse(results.getMetrics().getTotalTime() == -1);
FacetResult[] facets = results.getFacetResults();
assertNotNull(facets);
assertEquals("expected 1 facet", 1, facets.length);
FacetValue[] facetVals = facets[0].getFacetValues();
assertEquals("expected 6 facet values", 6, facetVals.length);
MatchDocumentSummary[] summaries = results.getMatchResults();
assertNotNull(summaries);
assertEquals("expected 2 results", 2, summaries.length);
}
内容来源于网络,如有侵权,请联系作者删除!