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

semerau at hotmail.com semerau at hotmail.com
Wed Aug 18 15:08:19 PDT 2010


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


More information about the General mailing list