6

Is sort-order by path-index already supported in ML 8? I want to achieve similar to the below:

<options xmlns="http://marklogic.com/appservices/search">
  <sort-order collation="http://marklogic.com/collation/en/S1/EO/CU/MO" type="xs:string" direction="ascending">
    <path-index>attritbutes//name</path-index>
  </sort-order>
</options>

If not, is there a way to achieve this? I have several elements with the same name from different parent nodes or from the root element so I can't use just

<options xmlns="http://marklogic.com/appservices/search">
  <sort-order collation="http://marklogic.com/collation/en/S1/EO/CU/MO" type="xs:string" direction="ascending">
    <element ns="" name="name"/>
  </sort-order>
</options>

3 Answers 3

9

According to the docs:

The sort-order element must have one of a single element child, a single score child, a single field child, or a single json-property child.

So you can't have a path child, but there is a way. Create a field based on the path(s) you want to use, then sort based on that field.

2
  • Creating a field!! Great solution :) Commented Jul 24, 2017 at 15:43
  • 1
    As noted by @Dixit in a comment below, don't forget to create a Field Range Index based on your field! They are necessary for sorting. Also, when used for sorting, field's can have no more than one include, and don't necessarily need any (you can use an explicit path for your field that points directly at the element to be sorted - necessary in my case as my whole approach was trying to avoid issues with multiple same localnames in a document, and includes will still return a many items in sequence forest error if there is more than one localname for what you're including). Commented Jul 24, 2017 at 15:53
2

There is a schema bug in 8.0-1 so that sort-order/path-index does not validate.

However, the code implements support for sort-order/path-index, so if you don't validate the options, it should work. It might be better, however, to use a field as Dave suggests so you can continue to use validation to check for errors.

The schema bug is fixed in 8.0-2.

1
  • "the code implements support for sort-order/path-index" Is this true? I was not able to find any reference to this in the documentation (ML v9), and had no luck implementing it this way (I eventually resorted to @Dave's field solution). Commented Jul 24, 2017 at 15:46
2

Yes, Create a field on 'name' element

<options xmlns="http://marklogic.com/appservices/search">
  <sort-order type="xs:string" 
              collation="http://marklogic.com/collation/" 
              direction="ascending">
    <field name="name"/>
  </sort-order>
</options>
3
  • 1
    While creating a field on name element, create range index (there is an option to create range index while defining field) also else an error will be thrown. Commented Apr 25, 2017 at 8:37
  • @Dixit important note! Field Range Indexes are necessary for sort (you create a field range index based on your field). Commented Jul 24, 2017 at 15:49
  • @FatehKhalsa Thanks, But I said the same thing in the comment :) Commented Jul 25, 2017 at 6:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.