From: Oystein R. <oys...@ak...> - 2007-10-04 08:09:30
|
Hi I'd be very grateful if somebody could help me with the following problem. ((Btw - thanks to Adam Retter and Wolfgang Meier for helpful feedback to a question I asked a month ago.)) I make an application to search a collection of documents. The number of documents in the collection will lie in the range of 1,000 to 100,000 documents. Each document can have one or more authors (say, 1.5 authors on average). I want to search the documents and order the result on author. I want the documents with more than one author to appear several times in the result list - once for each author. (In addition I want to present the result list in chunks, say 100 entries at a time.) I think results will typically have tens or hundreds or thousands of documents. I might also have to be prepared for queries that return almost the whole collection. Below is the query I've come up with. Can it be done more efficiently? The sorting seems to take a very long time. Is there anything that can be done to speed it up? My application is web-based, with a java servlet doing the query via XMLDB (I might change to REST). Could time be saved by the servlet doing the sorting???? (: Calculate extent of chunk :) let $chunkStart := ...... let $chunkLen := 100 let $chunkEnd := $chunkStart + $chunkLen (: position where next chunk starts :) (: Search. Get a list of (document, author) pairs. This list should be as "lean" as possible :) let $pairList := ( for $document in collection('mycollection')//document[...predicate with search criteria...] for $author in $document/author return element pair { $document, $author } ) (: Sort. Extract chunk :) let $chunk := ( for $pair in $pairList order by $item/author return $pair )[position() >= $chunkStart and position() < $chunkEnd] (: Process and return chunk :) for $pair in $chunk return element entry { $pair/author/......, $pair/document/......, ... } - Øystein - -- Øystein Reigem, The department of culture, language and information technology (Aksis), Allegt 27, N-5007 Bergen, Norway. Tel: +47 55 58 32 42. Fax: +47 55 58 94 70. E-mail: <oys...@ak...>. Home tel: +47 56 14 06 11. Mobile: +47 97 16 96 64. Home e-mail: <or...@br...>. Aksis home page: <www.aksis.uib.no>. |