Sini,
xdmp:estimate() works on a special class of expressions that would normally
return a set of documents or elements. In particular it works on a cts:search()
expression. Another way to think of it is that xdmp:estimate() is a very fast
version of fn:count() that only works on "searchable expressions."
Here is a sample query that illustrates it's use:
let $cts-version as cts:query := cts:word-query("run")
return xdmp:estimate(cts:search(doc(), $cts-version))
Here is a modification that also illustrates converting back and forth from the
special cts:query type and it's XML representation:
let $query as element() := <x>{cts:word-query("run")}</x>/node() (: embed a
cts:query into XML to serialize it to XML :)
let $cts-version as cts:query := cts:query($query) (: this is to parse the
XML serialization of the query, which you'll use to convert output from
search:parse() :)
return xdmp:estimate(cts:search(doc(), $cts-version))
So your problem may have been twofold;
1) You can't do xdmp:estimate() directly on a query structure - you need a
full cts:search() call or XPath expression in there.
2) xdmp:estimate() is part of the low-level search api, along with
cts:search(), that uses cts:query constructs. search:search() and
search:resolve() use the XML serialization of those cts:query structures, so
for xdmp:estimate(), you need to convert via cts:query()
Yours,
Damon
--
Damon Feldman
Sr. Principal Consultant, MarkLogic
From: [email protected]
[mailto:[email protected]] On Behalf Of sini narayanan
Sent: Thursday, March 21, 2013 10:21 AM
To: MarkLogic Developer Discussion
Subject: [MarkLogic Dev General] search:estimate
Hi All,
I'm trying to get the total number of results returned after executing a query.
The below code is working fine, but returns only 10 results (default
page-length). But the total result count is 69.
(:All the import statements are provided :)
let $exportQuery :=
'{"query":{"and-query":{"queries":[{"range-constraint-query":{"constraint-name":"city","value":["Paris
01"]}}]}}}'
let $options := xdmp:http-get("http://localhost:6024/v1/config/query/all",
<options xmlns="xdmp:http">
<authentication method="digest">
<username>admin</username>
<password>admin</password>
</authentication>
<format xmlns="xdmp:document-get">xml</format>
</options>)//search:options
let $query :=
json:transform-from-json($exportQuery,$sut:json-config-query)
let $searchResults := search:resolve($query, $options)
return $searchResults
I was trying to use the "search:estimate" command to get the total count of
results. But when I execute the command
let $totalItems := search:estimate($query) (:$query being the same as above
code:)
it is throwing some exception.
How do I use search:parse on this $query, which is transformed from json?
I need the $totalItems to return 69.
Any help on this regard would be helpful.
Thanks,
Sini
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general