[MarkLogic Dev General] How to use cts:search to query documents and their properties?

Michael Blakeley michael.blakeley at marklogic.com
Tue Oct 28 09:20:10 PST 2008


Bindu,

This might be a good time to ask whether properties are the right 
implementation for your metadata. The important feature of properties is 
that they are *not* part of the document. This separation has certain 
benefits, but if you want to search for two facts together, then 
properties are not the right tool for the job. Instead, both facts 
should live in the same document.

One common approach is to include a "metadata" element within each 
document (you could name the element "inline-properties", if that 
helps). Both this metadata and the original content are under a common 
root, which could be any element you like:

<wrapper>
   <metadata>
     <!-- extra content goes here -->
   </metadata>
   <original-content>
     <!-- original content goes here -->
   </original-content>
</wrapper>

Now you can search for facts within the original content, plus the extra 
content. At the same time, you have not made any changes to the original 
content. This can also be a way to handle document-level enrichment: 
adding elements that are specially normalized for sorting, adding user 
tags, etc.

But, you might ask, what if some of my content is binary, and I want to 
use the same metadata with it? Where do the properties go? That's a good 
question - and we can still use the same approach as above. But instead 
of setting properties on the binary document, we use an ordinary XML 
document as a proxy for the binary.

<wrapper>
   <metadata>
     <!-- extra content go here -->
   </metadata>
   <binary uri="..."/>
</wrapper>

The binary element is a proxy for a binary document elsewhere in the 
database. It doesn't actually have to point to the binary uri, of 
course: you could choose to use a well-known convention for uri format, 
instead, so that you can always construct the binary uri from the proxy 
uri, and vice-versa.

-- Mike

Bindu Wavell wrote:
> I understand how to perform a cts:search against all the documents in  
> a folder. I can also perform a cts:search against property documents.
> 
> Is it possible to treat a document and it's properties as a single  
> element for search or combine the doc() and xdmp:document-properties()  
> in some way in for the $expression argument to cts:search...
> 
> I want to find all occurrences of the word "foo" in the content and/or  
> the properties for the content...
> 
> Thanks,
> 
> 
> -- Bindu Wavell
> Consultant
> Flatirons Solutions, Corp
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://xqzone.com/mailman/listinfo/general



More information about the General mailing list