[MarkLogic Dev General] How to query all docs and sort by last-modified property?

Danny Sokolsky Danny.Sokolsky at marklogic.com
Wed Aug 18 14:51:49 PDT 2010


If you search over the properties you can get this to work.  I cannot immediately think of how you can do this using the search API without searching over the properties.  Here is how to do it by searching over the properties (you need a dateTime range index on prop:last-modified for this to be optimized):

xquery version "1.0-ml";

import module namespace search = "http://marklogic.com/appservices/search"
at "/MarkLogic/appservices/search/search.xqy";
declare namespace prop="http://marklogic.com/xdmp/property";

let $options :=
<options xmlns="http://marklogic.com/appservices/search">
  <searchable-expression>xdmp:document-properties()
  </searchable-expression>
  <debug>true</debug>
  <term>
   <empty apply="all-results" />
  </term>
  <sort-order type="xs:dateTime" direction="descending">
    <element ns="http://marklogic.com/xdmp/property" name="last-modified"/>
  </sort-order>
</options>

return
search:search("", $options)

-Danny

From: general-bounces at developer.marklogic.com [mailto:general-bounces at developer.marklogic.com] On Behalf Of semerau at hotmail.com
Sent: Wednesday, August 18, 2010 1:02 PM
To: general at developer.marklogic.com
Subject: [MarkLogic Dev General] How to query all docs and sort by last-modified property?

I have xml files in the database with the root element of "image". What I want to do is to use search:search to query all the image elements (no search term) and order them by the last-modified property.

Below is what I have tried, but it doesn't seem to actually be sorting on the last-modified property (I do already have an element range index on the property). It just returns hits based on relevance which is meaningless in this type of query.

Does anyone know how I can get this to work?

xquery version '1.0-ml';

import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy";

let $options :=
      <options xmlns="http://marklogic.com/appservices/search">
            <searchable-expression xmlns="http://marklogic.com/appservices/search">/image</searchable-expression>
            <search:sort-order type="xs:dateTime" direction="descending">
                  <search:element ns="http://marklogic.com/xdmp/property" name="last-modified"/>
            </search:sort-order>
      </options>

return search:search("", $options, 1, 16)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20100818/0b23f481/attachment-0001.html 


More information about the General mailing list