Ningjun, I believe you want to use a cts:document-query() with the thousands of URI's to constrain your search. Set this as an <additional-query> in search:search().
That's if your restriction is on the MarkLogic URIs for each document. If you actually have URL's encoded in the documents in a <url> element or similar, use cts:element-value-query(xs:QName("url"), $doc-urls) as the additional query. Yours, Damon From: general-boun...@developer.marklogic.com [mailto:general-boun...@developer.marklogic.com] On Behalf Of Wang, Ningjun (LNG-NPV) Sent: Friday, June 10, 2011 10:14 AM To: General MarkLogic Developer Discussion Subject: [MarkLogic Dev General] How to do keyword search within a set of dicuments returned by some function. We have a requirement to do keyword search on a set of documents returned by some function. For example the function getRelatedDocUrls() return a list of document URLs (could be hundreds of thousands of document). I need to do a keyword search within those documents and return the correct total count and return result with 10 documents per page. What is the most efficient way to do that? One option I am thinking is to do the keyword search first then join the result with the set of documents, e.g. Let $urls := getRelatedDocUrls() for $result in search:search(keyword)/search:result, $url in $urls where $result/@uri = $url There are two problems 1. search:search(keyword) return one page at a time. Suppose I make it return 20 docs per page, then the first page may not have any document matching $urls. 2. search:search(keyword) return the total count of document matching keyword. However I want the total count of documents not only matching the keyword, but also with url in $urls Of course I can make search:search(keyword) to return all result in one page and then through the join to find out the answer above. However this will be very inefficient because search:search(keyword) can return millions of documents. I just want the correct total count and the first 10 documents that match the keyword and with url match $urls. What is the most efficient way to do this? Thanks Ningjun Wang Consulting Software Engineer LexisNexis Global Solutions Dev New Providence, NJ (908) 665-6787
_______________________________________________ General mailing list General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general