【问题标题】:How to fetch all documents that match a URI pattern in Marklogic如何在 Marklogic 中获取与 URI 模式匹配的所有文档
【发布时间】:2015-02-09 14:39:46
【问题描述】:

我开始学习 marklogic 的 java api,我想知道如何获得所有符合特定 URI 模式的文档。

例如我想从 URI 模式所在的 ML db 中获取所有文档 "/Downloads/Current/com.crc.eng.dollar/*"

【问题讨论】:

    标签: marklogic


    【解决方案1】:

    您可以查询目录中的文档。以下几行应该可以工作:

    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;
        }
    }
    

    为了提高查询效率,将查询选项保留为空,并将 sn-p 转换设置为空,并在创建查询构建器时标识查询选项。

    如果所有文档都是 JSON 或 XML,您可以使用更具体的文档管理器。

    顺便说一句,在 MarkLogic 8 中,查询将能够直接返回一页文档。

    更多信息:

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

    【讨论】:

      【解决方案2】:

      我使用的是 XQuery API 而不是 Java API,但也许您可以尝试通过 XCC 使用 cts:uri-match(请参阅:http://docs.marklogic.com/cts:uri-match

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-18
        • 1970-01-01
        • 1970-01-01
        • 2011-04-26
        • 1970-01-01
        • 2012-07-16
        相关资源
        最近更新 更多