的第一步是使数据库的URI的词汇。
你可以EVAL一些XQuery和运行CTS:URI的()(或服务器端JS和运行cts.uris()):
ServerEvaluationCall call = client.newServerEval()
.xquery("cts:uris()");
for (EvalResult result : call.eval()) {
String uri = result.getString();
System.out.println(uri);
}
两个缺点是:(1)你需要一个用户privileges和(2)没有分页。
如果您有少量文件,则不需要分页。但是对于大量的文档分页建议。下面是使用搜索API和分页一些代码:如果您需要添加/删除在这个过程中发生的同时分离出一种保证“快照”列表
// do the next eight lines just once
String options =
"<options xmlns='http://marklogic.com/appservices/search'>" +
" <values name='uris'>" +
" <uri/>" +
" </values>" +
"</options>";
QueryOptionsManager optionsMgr = client.newServerConfigManager().newQueryOptionsManager();
optionsMgr.writeOptions("uriOptions", new StringHandle(options));
// run the following each time you need to list all uris
QueryManager queryMgr = client.newQueryManager();
long pageLength = 10000;
queryMgr.setPageLength(pageLength);
ValuesDefinition query = queryMgr.newValuesDefinition("uris", "uriOptions");
// the following "and" query just matches all documents
query.setQueryDefinition(new StructuredQueryBuilder().and());
int start = 1;
boolean hasMore = true;
Transaction transaction = client.openTransaction();
try {
while (hasMore) {
CountedDistinctValue[] uriValues =
queryMgr.values(query, new ValuesHandle(), start, transaction).getValues();
for (CountedDistinctValue uriValue : uriValues) {
String uri = uriValue.get("string", String.class);
//System.out.println(uri);
}
start += uriValues.length;
// this is the last page if uriValues is smaller than pageLength
hasMore = uriValues.length == pageLength;
}
} finally {
transaction.commit();
}
交易才是必需的。由于它增加了一些开销,如果你不需要这样的精确度,可以随意删除它。
你究竟在努力完成什么?如果你想导出内容,MLCP会更容易。如果您想要进行一些数字运算,那么在MarkLogic内部进行操作可能会更容易。 –