Count documents in a database directory

Say I have 50 entries in a directory /examplein a MarkLogic database. Is there any way to find the size of the directory? In this case, I should be 50. I need this in the search API.

Thanks in advance

+4
source share
2 answers
xdmp:estimate(cts:search(fn:doc(), cts:directory-query("/example/", "infinity")))

Use xdmp: estimate via fn: count to get a quick answer.

+8
source

using java api you can search a specific directory and then get the total number of hits.

    DatabaseClient client = DatabaseClientFactory.newClient(host,port, "admin", "****", Authentication.DIGEST);
    QueryManager queryMgr = client.newQueryManager();
    StructuredQueryBuilder qb = new StructuredQueryBuilder();
    StructuredQueryDefinition querydef = 
            qb.directory(true, "/content/enhanced-rosetta/");
    SearchHandle resultsHandle = queryMgr.search(querydef,new SearchHandle());
    MatchDocumentSummary[] results = resultsHandle.getMatchResults();
    System.out.println("Total count=" + resultsHandle.getTotalResults());
    client.release();
+3
source

Source: https://habr.com/ru/post/1569276/


All Articles