Loading TOC...

MarkLogic 10 Product Documentation
search:estimate

search:estimate(
   $cts-query as element(),
   [$options as element(search:options)?]
) as xs:unsignedLong

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

xquery version "1.0-ml";
import module namespace search = "http://marklogic.com/appservices/search"
    at "/MarkLogic/appservices/search/search.xqy";

search:estimate(search:parse("merry"))

(: Returns an estimate of the number of fragments matching the
   word query produced by search:parse.
 :)
    

Example

xquery version "1.0-ml";
import module namespace search = "http://marklogic.com/appservices/search"
    at "/MarkLogic/appservices/search/search.xqy";

search:estimate(cts:word-query("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.