Loading TOC...

MarkLogic 9 Product Documentation
search.estimate

search.estimate(
   cts-query as Node,
   [options as element(search.options)?]
) as (Number|String)

Summary

This function quickly estimates the number of hits a query will return. The result is unfiltered and reflects the index resolution of the search.

Parameters
cts-query A cts:query object or serialized cts:query.
options Search API query options with which to customize the search. For details, see Appendix: Query Options Reference in the Search Developer's Guide.

Usage Notes

This function is equivalent to calling xdmp:estimate in XQuery with a cts:search expression, or to calling cts.estimate in Server-Side JavaScript, except that this function enables you to include Search API query options in the search. For example, the following calls are equivalent:
(: XQuery :)
xdmp:estimate(cts:search(fn:doc(),cts:parse("merry")))
search:estimate(search:parse("merry"))

// JavaScript
cts.estimate(cts.wordQuery("merry");
cts.search(search.parse("merry"));

Example

const search = require('/MarkLogic/appservices/search/search');

search.estimate(search.parse('merry'));

// Returns an estimate of the number of fragments matching the
// word query produced by search.parse. 
   

Example

const search = require('/MarkLogic/appservices/search/search');

search.estimate(cts.wordQuery('merry'));

// Returns an estimate of the number of fragments matching the word query.
   

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.