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

Michael Blakeley mike at blakeley.com
Fri Nov 4 07:45:36 PDT 2011


Right, and you can read about that at http://docs.marklogic.com/5.0doc/docapp.xqy#display.xqy?fname=http://pubs/5.0doc/xml/performance/order_by.xml

This tutorial might help too: http://developer.marklogic.com/learn/2006-09-paginated-search

Any new application should consider using the search API, which can handle sorting for you: http://docs.marklogic.com/5.0doc/docapp.xqy#display.xqy?fname=http://pubs/5.0doc/xml/search-dev-guide/search-api.xml%2330002

-- Mike

On 4 Nov 2011, at 07:31 , John Zhong wrote:

> 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
> 
> 
> _______________________________________________
> General mailing list
> General at developer.marklogic.com
> http://developer.marklogic.com/mailman/listinfo/general



More information about the General mailing list