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
xdmp:estimate(cts:search(fn:doc(), cts:directory-query("/example/", "infinity")))
Use xdmp:estimate over fn:count to get a fast response.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With