Reputation: 769
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.
Upvotes: 5
Views: 514
Reputation: 361
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.
Upvotes: 5
Reputation: 7842
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.
Upvotes: 0