4

Say I have 50 records in directory /example in a MarkLogic database. Is there any way to find size of directory? In this case it should give me 50. I need it in search API.

Thanks in advance

2 Answers 2

9
xdmp:estimate(cts:search(fn:doc(), cts:directory-query("/example/", "infinity")))

Use xdmp:estimate over fn:count to get a fast response.

3
  • 3
    Also, if you prefer the Search API, you can do the same thing with search:estimate().
    – ehennum
    Dec 29, 2014 at 16:03
  • 3
    Or the tersest form is probably xdmp:estimate(xdmp:directory($uri, 'infinity'))
    – mblakele
    Dec 29, 2014 at 17:37
  • Thanks Dave. I'm curious how we do the same with Java API?
    – Y.Prithvi
    Dec 30, 2014 at 6:40
3

with the java api you could do a search for a given directory and then get the total nr 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();
1
  • how efficient is that?
    – Hlib Babii
    Sep 3, 2015 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.