Sorting search results in a query can only be done on direct properties of documents
You typically order your query results in a specific way:
HstQuery hstQuery = context.getQueryManager().createQuery(scope, BaseDocument.class, true); // order by property "mynamespace:date", descending hstQuery.addOrderByDescending("mynamespace:date"); // and if the dates are the same, order by property "mynamespace:title", ascending hstQuery.addOrderByAscending("mynamespace:title");
As seen above, you can sort on properties like "mynamespace:date" and "mynamespace:title". These properties must be stored directly on the node representing a single query result. You cannot sort on properties in descendant JCR nodes (representing f.e. compound document fields). So if you have a compound type field in a document stored in child node " mynamespace:address", and that node has a property " mynamespace:street", then it is not possible to sort the search results on this property.
The reason for this limitation is twofold:
If your query result node has child nodes with the same name (same name siblings), then it is unclear which child node to use for the sorting. For example, if your document has two addresses, and you want to sort them by street name, which address should be used?
It cannot perform, as it cannot be indexed properly: Think about sorting on a property of a descendant node 5 levels deeper. This cannot be indexed, and therefore cannot be searched efficiently.