We are using the QueryBuilder API and are trying to write a query that should return assets ordered by the same order as they have in the DAM (i.e. by the index number shown in the leftmost column when viewing the assets underneath a folder in the DAM). If we do not specify an "order by" predicate the assets are ordered ascending by last modified date. Looking at the asset nodes in CRX, they don´t seem to have any property containing the index which could be used for such an ordering. Is such a query possible to write?
I don't think there is any special predicate to do that, Code is simply getting all children of given asset and returning them (Offcource there is some ordering logic). If You want exact informaiton I would suggest to use json call that DAM is making i.e.
HOST:POST/<PATH OF DAM>.assets.json
Or decompile AssetListServlet.java ans see how it is implemeted
Thanks for your reply Yogesh, that servlet obviously lists the assets in the same order as displayed in the DAM, but we need to execute a query using the Query Builder API (in which we use parameters to filter the result on path, tags, properties etc) and need a sorted result. If you just grab the parent sling:OrderedFolder JCR node in the DAM which contains the assets and do folder.getNodes() (or if you grab it as a Resource and do resource.listChildren()), the assets are returned in the correct order (I guess that might be what the AssetListServlet does behind the scenes?)
i'm pretty sure (without decompiling) that the AssetListServlet "lists" the children of the node (resolver.listChildren(res)) - this would give you the natural order (which is used in the DAM admin).
so to your last question: no - it is not possible to write such a query - and it is not necessary ;-).
Anyway - using the given hierarchy in crx and accessing the stuff direct with the JCR api's without querying is always the prefered (optimized) way to get content out of the repository.
If you want to list assets of a given folder in the order they appear in the DAM admin, do not use a query! Use either the JCR API or the Sling Resource API, as the first one returns the children in the order they are saved in teh Repository, and the Sling API only abstracts from the nodes, but does not change the ordering.
In general do not write a query in that case. The performance penalty compared to simple using JCR API might be very high, especially with large repositories.