5

I have an element DateTimeList with PathRangeIndex for its first child element as follows:

/ResultPage/DateTimeList/DateTime[1]

Usually we sort an element with attribute as follows:

<sort-order type="xs:string" direction="ascending">
    <element ns="" name="div"/>
    <attribute ns="" name="order"/>
</sort-order>

Is there any similar way to sort DateTimeList element, using its first child element (using the path-range-index). I tried as follows:

<sort-order direction="ascending" type="xs:dateTime">
   <path-index>/ResultPage/DateTimeList/DateTime[1]</path-index>
</sort-order><sort-order><score/></sort-order></state></operator>

But got the result with no change as follows:

<DateTimeList>
   <DateTime>2014-05-07T10:26:00</DateTime>
</DateTimeList>
<DateTimeList>
   <DateTime>2013-12-01T00:00:00</DateTime>
   <DateTime>2014-05-01T00:00:00</DateTime>
   <DateTime>2014-12-01T00:00:00</DateTime>
</DateTimeList>
<DateTimeList>
   <DateTime>2013-09-01T10:32:42</DateTime>
</DateTimeList>
<DateTimeList>
   <DateTime>2014-05-30T00:00:00</DateTime>
   <DateTime>2015-05-30T00:00:00</DateTime>
</DateTimeList >

Thanks.

Sofia
  • 771
  • 1
  • 8
  • 22
  • 1
    Could you rerun with the debug option set http://docs.marklogic.com/guide/rest-dev/appendixb#id_57802 and report back? – Eric Bloch Sep 25 '13 at 16:15
  • I returned with the debug option set and got the error as follows: XDMP-LEXVAL: xs:boolean("") -- Invalid lexical value "" – Sofia Oct 08 '13 at 06:34
  • 1
    For anyone else looking for a solution - use a `field` as per: https://stackoverflow.com/a/28516625/2155673 – Fateh Khalsa Jul 24 '17 at 15:57

2 Answers2

5

The current releases of MarkLogic Search API actually don't support sorting by path-index. However you have constructed an expression that will work once that support is in the product. There are plans to introduce it.

I'd recommend using search:check-options($options) to see whether or not your options are valid. I believe in this case check-options will report that the node is not valid.

Sofia
  • 771
  • 1
  • 8
  • 22
grechaw
  • 361
  • 1
  • 5
0

There isn't quite enough information here to reproduce the problem, but are all those DateTimeList elements in the same document? Or are there multiple DateTimeList elements per document?

Searching and sorting mostly happen at the document level. MarkLogic is a document-oriented database. So indexes point to documents, which act something like rows in an RDBMS table.

If that is it, consider breaking up the documents. It's technically possible to fragment on, say, DateTimeList and add a searchable-expression on //DateTimeList. But my experience is that it's better to structure the documents at the right level to begin with.

mblakele
  • 7,782
  • 27
  • 45
  • 1
    4-different records gave that output which has been described above, a document have single DateTimeList element. – Sofia Sep 26 '13 at 13:33
  • Looks like http://markmail.org/message/d2gaoim4ibdlmywr has the answer. Until that's fixed in `search.xqy`, you'd have to call `cts:search` directly to make this work. That post also included the excellent advice to try `search:check-options` when debugging problems with the search API. – mblakele Sep 26 '13 at 21:34