I have around 20 lacs documents in Marklogic Database. I want the total number of documents in my search application for pagination. For getting the totals I am using
xdmp:estimate(cts:search(doc(), $query))
where $query is the combination of various queries combined in cts:and-query
. But I am not getting the correct total. When $query is blank it shows much higher count than the total number of documents in the database. When I use
xdmp:estimate(doc())
it shows me the correct total but it would be static total which would not change according to the query. I want the total according to the results returned in response to a particular query that's why I passed $query as an argument but it is not showing correct total. fn:count()
shows correct total but when the number of documents are around 20 lacs then fn:count()
does not work because fn:count()
is slower than xdmp:estimate()
.
Please help me to get the correct total number of documents returned in response to the search term entered by the user.