Hi, Sini:

search:resolve() and search:search() both return a <search:response> element, 
not a document wrapping the search:response element.

If you are setting $searchResults to the return value, the XPath will fail 
because it searches for search:response inside itself.

This can be tricky to diagnose because the document node has no output.  
Sometimes it can be useful to do an xdmp:log() of xdmp:node-kind() on the 
context node of the XPath just to check where the matches will start.  Please 
see:

    http://docs.marklogic.com/xdmp:node-kind

Anyway, try

    return $searchResults/@total/string()

That said, on the general point, if you are searching twice (once to get the 
estimate and again to get the actual results), it would be far better just to 
set the maximum statically to the largest number you can reasonably process.  
By data type, the result ceiling can be set to the maximum unsigned long, but 
as Damon has noted, that's unrealistically large.


Hoping that's useful,


Erik Hennum

________________________________
From: [email protected] 
[[email protected]] on behalf of sini narayanan 
[[email protected]]
Sent: Thursday, March 21, 2013 10:26 PM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] search:estimate

Hi Eric,

I get the search results as below (return $searchResults)

<search:response snippet-format="snippet" total="69" start="1" page-length="10" 
xmlns:xs="http://www.w3.org/2001/XMLSchema"; xmlns="" 
xmlns:search="http://marklogic.com/appservices/search";>
  <search:result ......
  ........
  ........
</search:response>



Why is that, it is not returning any value when I perform the below return 
statement ?

return $searchResults//search:response/@total/string()


Thanks,
Sini


On Thu, Mar 21, 2013 at 8:33 PM, Erik Hennum 
<[email protected]<mailto:[email protected]>> wrote:
Hi, Sini:

I neglected to mention a couple of points that might be useful.

The search response has a total attribute that provides the estimate.

I assume you are writing XQuery in QueryConsole to prototype some client code.  
If that's not the case, you might consider stating the query in XML rather than 
in JSON to skip the transform step and thus simplify the processing.


Erik Hennum
________________________________
From: 
[email protected]<mailto:[email protected]>
 
[[email protected]<mailto:[email protected]>]
 on behalf of Erik Hennum 
[[email protected]<mailto:[email protected]>]
Sent: Thursday, March 21, 2013 7:37 AM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] search:estimate

Hi, Sini:

If you need to return all results, you could increase the page length in the 
query options to the largest number of results that you would reasonably want 
to return.


Hoping that helps,


Erik Hennum

________________________________
From: 
[email protected]<mailto:[email protected]>
 
[[email protected]<mailto:[email protected]>]
 on behalf of sini narayanan 
[[email protected]<mailto:[email protected]>]
Sent: Thursday, March 21, 2013 7:20 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]<mailto:[email protected]>
http://developer.marklogic.com/mailman/listinfo/general


_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to