When using MarkLogic 7 with the Java Client API, I am currently in the process of moving my query definitions from a StringQueryDefinition to a StructuredQueryDefinition allowing me to construct and manipulate the query programmatically.
With the string query I was able to use the sort operator with sort:{my-sort-order} successfully which in turn referred to names of predefined orders as specified in the query options (https://docs.marklogic.com/guide/search-dev/query-options#id_30002), but cannot find the API docs a related method allowing me to specify the sort order with the structured query builder.
What is the recommended way on how to specify the sort order when using a StructuredQueryDefinition?
UPDATE
Based on Erik's proposal, this is how the code snippet currently looks like, but it doesn't solve the problem, since the operator-state has to go as child on the query element and not as child on the search element:
RawStructuredQueryDefinition queryDef = qb.build(qb.and(qb.term(..), qb.rangeConstraint(...)));
String sorting = "<operator-state><operator-name>sort</operator-name><state-name>" + orderBy + "</state-name></operator-state>";
String combi = "<search xmlns='http://marklogic.com/appservices/search'>" + queryDef.toString() + sorting + "</search>";
RawCombinedQueryDefinition combinedQueryDef = queryManager.newRawCombinedQueryDefinition(new StringHandle(combi), OPTIONS);
// DOES NOT WORK, but will lead to MarkLogicIOException "Could not construct search results: parser error"
// Possible solution is to modify the queryDef DOM your own