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: [email protected] 
[mailto:[email protected]] On Behalf Of 
[email protected]
Sent: Wednesday, August 18, 2010 1:02 PM
To: [email protected]
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)
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to