Thanks for the response, Geert and Ryan. Actually it turns out that
there is some magic afoot, because the cast is not actually needed. I
think it used to be in older MarkLogic versions.
xdmp:query-trace(true()),
(
for $doc in xdmp:directory ("/product/")
order by $doc//sortdate descending empty least
return ...
)[1 to 20]
runs fast, with the index (23 msec as opposed to 9+ sec when the 50,000
docs need to be scanned)
However, interestingly, if you change the order (ascending instead of
descending) so that the empty items sort first, then the index is not
used, and the query is even slower (14+ seconds)
On 07/12/2012 08:38 AM, Geert Josten wrote:
> Hi Mike,
>
> Did you try:
>
> order by $doc//sort-date/xs:date(.)
>
> ?
>
> Kind regards,
> Geert
>
>
>> -----Oorspronkelijk bericht-----
>> Van: [email protected] [mailto:general-
>> [email protected]] Namens Michael Sokolov
>> Verzonden: donderdag 12 juli 2012 14:29
>> Aan: MarkLogic Developer Discussion
>> Onderwerp: [MarkLogic Dev General] sorting by date
>>
>> I have a date-valued element range index. I want to use it for
>> sorting. When I do that using an expression like this:
>>
>> order by xs:date($doc//sort-date)
>>
>> I get errors when the $doc sequence contains documents that have no
>> sort-date.
>>
>> What is the recommended approach to handling nulls when sorting? Ideally
>> we would want them to sort last.
>>
>> If I just use
>>
>> order by $doc//sort-date
>>
>> will the index come in to play?
>>
>> -Mike Sokolov
>> _______________________________________________
>> General mailing list
>> [email protected]
>> http://developer.marklogic.com/mailman/listinfo/general
>>
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general
>
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general