[MarkLogic Dev General] How to sort search results, then page?

John Zhong john at yuxipacific.com
Fri Nov 4 07:31:14 PDT 2011


Hi Brent,

There are some tips about the order by optimization in the document
performance.pdf, chapter 4.0 Optimizing Order By Expressions With Range
Indexes, which is good to know.

Best Regards,
John

On Fri, Nov 4, 2011 at 10:06 PM, Brent Hartwig <bhartwig at reallysi.com>wrote:

> Good morning,****
>
> ** **
>
> I am trying to understand how to sort within cts:search(), before applying
> the paging parameters.  The code below only sorts the subset returned by
> cts:search()[$start to $end].  Is this what collations are for?  Do
> collations require range indexes?  Would search:search() make this easier?
> ****
>
> ** **
>
> The default sort will be against
> $node/rdf:Description/dcterms:identifier/oxdc:doi/rdf:value; but, the
> application is required to allow the users to sort by any column’s values
> (other elements).  Those sorts also need to apply to all results, rather
> than only those on the current page.****
>
> ** **
>
> Thank you in advance.****
>
> ** **
>
> *return*
> <list start="{$start}" end="{$end}" total="{xdmp:estimate(cts:search(/rdf:RDF,
> $recordQuery, 'unfiltered'))}">
> {
>     (: TODO: Order all results by DOI then return $start to $end :)
>     *for* $node *in* *cts:search*(/rdf:RDF, $recordQuery, 'unfiltered')[$start
> *to* $end]
>     *order by* $node/rdf:Description/dcterms:identifier/oxdc:doi/rdf:value
>     *return*
>     <item>
>         <doi>{$node/rdf:Description/dcterms:identifier/oxdc:doi/rdf:value/
> text()}</doi>
>         <title>{$node/rdf:Description/dcterms:title/text()}</title>
>         <products>
>         {
>         *for* $productCode *in* $node/rdf:Description/
> oxdc:resourceIdentifiers/oxdc:productCode/text() *return*
>            <product>{$productCode}</product>
>         }
>         </products>
>     </item>
> }
> </list>****
>
> ** **
>
> -Brent****
>
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://developer.marklogic.com/mailman/listinfo/general
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20111104/b7280378/attachment.html 


More information about the General mailing list