I think the first step is to rewrite that isbn query without using xdmp:value. 
From what I can see, there is no reason to use xdmp:value there. You should be 
able to compose the whole cts:or-query using cts:query constructors.

Once you have done that, the performance problem may become clearer. As Danny 
mentioned, the update transaction is probably locking a large number of 
documents. Your next step will probably be to switch from cts:search to 
cts:uris.

Also, the error-checking code at the end is a bit misguided. The 
xdmp:document-add-collections function will never return a result: that's what 
empty-sequence() means in its function signature. If anything goes wrong with 
xdmp:document-add-collections, it will throw an error and your query will 
terminate. If you want to prevent that, use try-catch.

-- Mike

On 31 May 2012, at 07:14 , Ollier, John wrote:

> I have been trying to create/add to a collection of documents with a query
> like this:
> 
> define function addTitlesToCollection($collectionUri, $isbnList) {
>    let $isbn-query-string :=
> fn:concat('cts:search(fn:collection("my-main-collection"),cts:or-query((',
> getValueQueryStringForISBN($isbnList), ')),"unfiltered")')
>    let $search-documents := xdmp:value($isbn-query-string)
>    return <result>{
>        for $book in $search-documents
>            let $book-uri := fn:document-uri($book)
>            let $result :=
> xdmp:document-add-collections($book-uri,$collectionUri)
>            return if (fn:empty($result))
>                then <success>Successfully adding {$book-uri}  to collection
> {$collectionUri}</success>
>                else <error>Error adding {$book-uri} to collection
> {$collectionUri}</error>
>    }
>    </result>
> }
> 
> 
> It's extremely slow - adding 100 documents to the collection takes 6 minutes
> and I'd like to be able to add 1000.
> 
> I appreciate that the Marklogic documentation warns you that creating a
> collection is resource intensive. But is there any way of making it faster?
> I'm looking at handling the creation process asynchronously, but I'm
> concerned the fact that it's so slow means that the performance of Marklogic
> will be affected for other applications that use it. What the best way to
> check this?
> 
> Thanks in advance.
> 
> John
> 
> 
> 
> 
> ********************************************************************************
>    
> DISCLAIMER: This e-mail is confidential and should not be used by anyone who 
> is
> not the original intended recipient. If you have received this e-mail in error
> please inform the sender and delete it from your mailbox or any other storage
> mechanism. Neither Macmillan Publishers Limited nor any of its agents accept
> liability for any statements made which are clearly the sender's own and not
> expressly made on behalf of Macmillan Publishers Limited or one of its agents.
> Please note that neither Macmillan Publishers Limited nor any of its agents
> accept any responsibility for viruses that may be contained in this e-mail or
> its attachments and it is your responsibility to scan the e-mail and 
> attachments (if any). No contracts may be concluded on behalf of Macmillan 
> Publishers Limited or its agents by means of e-mail communication. Macmillan 
> Publishers Limited Registered in England and Wales with registered number 
> 785998 
> Registered Office Brunel Road, Houndmills, Basingstoke RG21 6XS   
> ********************************************************************************
> 
> _______________________________________________
> General mailing list
> [email protected]
> http://community.marklogic.com/mailman/listinfo/general
> 

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

Reply via email to