|
Sini -
Your first call to search:search will return at most 10 results (I think), the default. Therefore $no-of-pages will always be one (unless it returns 0 results). Then the second call to search:search asks for 1000 results, which is a very high number. This
is likely your problem. Do you need that many results?
It looks like you're using search API to gather URIs. cts:uris would be a better tool for that job.
-Will
From: sini narayanan <[email protected]>
Reply-To: MarkLogic Discussion <[email protected]> Date: Sunday, July 14, 2013 10:52 PM To: MarkLogic Discussion <[email protected]> Subject: [MarkLogic Dev General] SearchAPI using search:search() Hi All,
I'm creating a searchAPI that would perform search on a specific DB and sends back the xml response.
I have done this using search:search(). The code is working fine.
But when ever I perform a query for huge number of docs[say 90000 docs], it takes more than 10mnts to return the xml response.
Here is the code,
import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy";
let $searchTerm := "provider:collOne AND country:USA"
let $options := <options xmlns="http://marklogic.com/appservices/search">
<constraint name="country"><range type="xs:string"><element ns="" name="country"/><attribute ns="" name="countryCode"/></range></constraint>
<constraint name="provider"><collection prefix="/provider/"/></constraint>
<return-facets>false</return-facets>
<extract-metadata><qname elem-ns="" elem-name="name"/><constraint-value ref="country"/><constraint-value ref="provider"/></extract-metadata>
</options>
let $result := search:search($searchTerm,$options)
let $totalItems := data($result//@total)
let $pageSize := xs:integer(1000)
let $no-of-pages := xs:integer(math:ceil($totalItems div $pageSize))
let $index := xs:integer(1)
return
<results>{
for $i in (1 to $no-of-pages)
let $searchResults := search:search($searchTerm, $options ,$pageSize*($i - 1)+1, $pageSize)
for $current in $searchResults//search:result
let $URI := $current/@uri/string()
return
<doc URI="{$URI}"/>
}</results>
When I simply return the $result, it is very fast and the time it shows is <search:total-time>PT0.04323S</search:total-time> for 90000 docs.
But in the return, when I loop through the pages($no-of-pages), it takes a lot of time.
Please let me know if I'm performing something incorrect here.
Thanks,
Sini
|
_______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
