You don't really explicitly create a collections, generally you will either 
specify the collection(s) for a document when you insert it or you can update 
the document using xdmp:document-add-collections().  Setting them at insert 
time is more ideal, that way you don't incur the extra update to add the 
collections.  You can also assign 1 or more default collections to a particular 
user or role via the Admin interface (Security->Users and Security->Roles).

How you add them at insert time will depend on how you're actually inserting 
your documents.  If you're using xdmp:document-insert() or xdmp:document-load() 
both of those functions have their own way of specifying collections when you 
insert the docs (see the API documentation for details).

As far as using the collections that you create at query time, there are a 
number of options.  One option is to use "cts:search( collection("my 
collection") ... )" as you describe.  This will be a searchable expression, and 
will search all documents within that collection.  You can also use 
cts:collection-query() which can be combined with your other query criteria 
using cts:and-query().  For example:

cts:search(fn:doc(), cts:and-query(( cts:collection-query("my-collection"), 
cts:word-query("dog") )))




From: [email protected] 
[mailto:[email protected]] On Behalf Of Lee, David
Sent: Saturday, November 21, 2009 12:39 PM
To: [email protected]
Subject: [MarkLogic Dev General] Creating Collections

I'm having fun now trying to search 2 documents at once with different 
structures (different root elements among other things)
I know I can put them into a directory and search them via
                cts:search( cts:directory("/dir/") , ...)

but I was trying to see what else I could do, so I tried this
                cts:search( doc("doc1" )/foo/bar | doc("doc2")/spam , ...)

"of course" that didnt work.  (an error about "Not searchable expression").

So what I've done is search twice then combine the results but it causes all 
sorts of unnecessary complexity,

                let $res := cts:search( ... )  | cts:search( ... )

for example the ordering now isn't by score anymore, so I have to add a 
for/order-by to re-order it.
Then the cts:remainder function doesnt work too good
                cts:remainder( $res[1] )
returns the remainder of the first search only.   So then I have to do some 
more fancy stuff to add 2 remainders ...
I bet you can see how this is going .. :)

So I'm looking around for a better way and ran into the collection concept.   
Is that how to solve this ? Create a collection ...
then is the collection searchable ?
                cts:search( collection("my collection") ... )

then the results would be combined right ?

SO ho DO I create a collection ? The only way so far I've found is   
xdmp:documents-add-to-collection()

Is that the only/correct way to create collections ?  Is there something on the 
admin panel that can do it ?

Any pointers to docs that describe collections would be appreciated.  All I 
could find is some very terse references to them but not how to actually create 
and use them.

Thanks for any suggestions !







----------------------------------------
David A. Lee
Senior Principal Software Engineer
Epocrates, Inc.
[email protected]<mailto:[email protected]>
812-482-5224


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

Reply via email to