Tuesday 2 August 2011

MarkLogic: Example Word Query Specification Template

Below is an example configuration for creating a custom word query specification on a given database:


Brajendu Kumar Das said...

How to sort all documents as per the creation time ?

Sir any solution pls... ?

Alex Bleasdale said...


You could use document-properties for this - here's a simplistic example:

for $d in doc()
order by $d/property::prop:last-modified
return xdmp:node-uri($d)

Note that this won't scale - it just illustrates the use of document properties.

Depending on the problem you're trying to solve, you could also iterate over the results from a cts:search using a similar technique.

You could also use the search API and pass the properties query in as an additional query or use xdmp:document-properties() as a searchable expression...

Alex Bleasdale said...

Having said that, I noticed you wanted to sort by creation time, not modified time. You could add the creation time as additional XML metadata to the document and set up a process which adds the dateTime stamp to the doc at the point where it's loaded into the database. Add an xs:dateTime range index to the element if you want to make it more performant...