How to get all documents matching the URI pattern in Marklogic

I am starting to learn java api for marklogic. What you need to know is how I can get all documents matching a specific URI pattern.

For example, I want to get all the documents from ML db, where the URI template is "/Downloads/Current/com.crc.eng.dollar/*"

+4
source share
2 answers

You can request documents in the catalog. Something in the following lines should work:

DatabaseClient         client    = DatabaseClientFactory.newClient(...);
GenericDocumentManager docMgr    = client.newDocumentManager()
QueryManager           queryMgr  = client.newQueryManager();
StructuredQueryBuilder queryBldr = new StructuredQueryBuilder();

for (int pageNo=1; pageNo < YOUR_MAXIMUM_BEFORE_STOPPING; pageNo++) {
    SearchHandle resultsHandle = queryMgr.search(
        queryBldr.directory(true, "/Downloads/Current/com.crc.eng.dollar/"),
        new SearchHandle(),
        pageNo
        );

    MatchDocumentSummary[] docSummaries = resultsHandle.getMatchResults();
    for (MatchDocumentSummary docSummary: docSummaries) {
        InputStreamHandle docHandle = docMgr.read(
            docSummary.getUri(), new InputStreamHandle()
            );
        // ... do something with the document ...
    }

    if (docSummaries.length < queryMgr.getPageLength()) {
        break;
    }
}

To make the query more efficient, save the query parameters with the fragment transformation set to empty and define the query parameters when creating the query builder.

JSON XML, .

, MarkLogic 8 .

:

http://docs.marklogic.com/javadoc/client/index.html http://docs.marklogic.com/guide/java

+3

API XQuery Java, , , cts: uri-match XCC (.: http://docs.marklogic.com/cts:uri-match)

0

All Articles