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:
final HstQuery hstQuery = HstQueryBuilder.create(scope) .ofTypes(BaseDocument.class) // order by property "myhippoproject:date", descending .orderByDescending("myhippoproject:date") // and if the dates are the same, order by property "myhippoproject:title", ascending .orderByAscending("myhippoproject:title") .build();
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.