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

Danny Sokolsky Danny.Sokolsky at marklogic.com
Wed Aug 18 15:31:33 PDT 2010


I can think of how to do this using cts:search, but I cannot think of a search API way to do this.

Here is the cts:search way:

xquery version "1.0-ml";

(for $x in cts:search( doc(), /image )
order by $x/property::prop:last-modified
return $x)[1 to 10]

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 3:19 PM
To: general at developer.marklogic.com
Subject: Re: [MarkLogic Dev General] How to query all docs and sort by last-modified property?

That would be adding information to the properties that was already in the document. Hopefully there's some better way.
________________________________
From: Danny.Sokolsky at marklogic.com
To: general at developer.marklogic.com
Date: Wed, 18 Aug 2010 15:14:17 -0700
Subject: Re: [MarkLogic Dev General] How to query all docs and sort by last-modified property?
If you added an <image> element to the properties for each document that was an image then I think an additional query would work.

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 3:08 PM
To: general at developer.marklogic.com
Subject: Re: [MarkLogic Dev General] How to query all docs and sort by last-modified property?

This is really close to what I need. Now I just need to constrain the results to only be for documents that have "image" for the root element. I tried adding this to the search options:

<additional-query>/image</additional-query>

but it didn't affect the results. I suppose because the "image" elements are already being retrieved by the searchable expression, adding any additional-query with do nothing, since everything is already satisfied in the properties query.

So how I can I just return the image documents, and sort them by last-modified?
________________________________
From: Danny.Sokolsky at marklogic.com
To: general at developer.marklogic.com
Date: Wed, 18 Aug 2010 14:51:49 -0700
Subject: Re: [MarkLogic Dev General] How to query all docs and sort by last-modified property?
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)

_______________________________________________ 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://developer.marklogic.com/pipermail/general/attachments/20100818/a13b9287/attachment-0001.html 


More information about the General mailing list