[MarkLogic Dev General] cts query for sorting

Michael Blakeley mike at blakeley.com
Thu Aug 9 11:34:14 PDT 2012


Not directly, but you might be able to use co-occurrences instead.

I don't think this is documented, but you can access the uri lexicon as if it were an element lexicon named xdmp:document in the codepoint collation. If you request the co-occurrences of contentCreated and xdmp:document, in that order, the results should be sorted by contentCreated. You can include a query, too.

cts:element-value-co-occurrences(
  xs:QName('contentCreated'), xs:QName('xdmp:document'),
  ('collation-2=http://marklogic.com/collation/codepoint'),
  $query)

To get just the URIs, add another XPath step to the expression.

cts:element-value-co-occurrences(
  xs:QName('contentCreated'), xs:QName('xdmp:document'),
  ('collation-2=http://marklogic.com/collation/codepoint'),
  $query)/cts:value[2]/string()

-- Mike

On 9 Aug 2012, at 07:14 , Alvaro San Millan wrote:

> Hi all,
> 
> I am having problem to find a cts query to sort the output of this query:
> 
> let $query := cts:and-query((
>   cts:directory-query("/mint/"),
>   cts:element-attribute-value-query(xs:QName("panar:pageInfo"), 
> xs:QName("idref"), "page1"),
>   cts:not-query(cts:element-query(xs:QName("nar:role"), 
> cts:and-query(()))),
>   cts:not-query(cts:element-query(xs:QName("df:dataFormat"), 
> cts:and-query(())))
> ))
> 
> let $uris := cts:uris(
>   '', ('document'), $query )
> return (count($uris), $uris)
> 
> 
> What I would like is to sort documents in /mint directory by 
> contentCreated, which is an element in those documents, and then return 
> the uris in ascending order by this contentCreated. Is there any cts 
> query to sort documents by an element in the xml files in /mint?
> 
> Kind Regards,
> 
>   Alvaro
> 
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://developer.marklogic.com/mailman/listinfo/general
> 



More information about the General mailing list