Hi, Sini: Instead of searching once to get the estimate and then getting a series of pages within the same request, it will be faster to just set $page-length to the largest number of results you would want to return and call search:search() once.
If you just want the document URIs, you can skip snippeting with an empty transform on the results: <search:transform-results apply="empty-snippet"/> As Will suggests, however, you cts:uris() will be faster if you really just need the uris of matching documents. You can use search:parse() to generate the query for cts:uris() Hoping that's useful, Erik Hennum ________________________________ From: [email protected] [[email protected]] on behalf of Will Thompson [[email protected]] Sent: Monday, July 15, 2013 8:03 AM To: MarkLogic Developer Discussion Subject: Re: [MarkLogic Dev General] SearchAPI using search:search() 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]<mailto:[email protected]>> Reply-To: MarkLogic Discussion <[email protected]<mailto:[email protected]>> Date: Sunday, July 14, 2013 10:52 PM To: MarkLogic Discussion <[email protected]<mailto:[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
