We have a JCR query which will get the result of pages based on jcr:title property. There is no issue in the query and it is working as expected. When we run the query in two different AEM versions(6.0 & 6.4) the order is not same but we see the exact result. Both AEM versions don’t have any custom index and sorting mechanism but the end result is not having any same order. Has there any order logic implemented in AEM 6.4? What should we do in order to get the same order in AEM 6.0 and AEM 6.4? Can anyone have any idea about it?
There are multiple ways to query AEM. As aemmarc says, Lucene scores your results and so order can differ from instance to instance.
You can however use a JCR SQL2 query to find your content. JCR SQL2 lets you use an ORDER BY clause to sort the results according as you wish (by date created, name, etc.). If you want to learn JCR SQL2, you can find a number of references with examples here, here or here for example.
To use a JCR SQL2 programmatically from Java, follow this example I created (sorry, indentation got a little messed up in transit):
final Query query = queryManager.createQuery(queryString, "JCR-SQL2"); query.setLimit(4); return query.execute(); }
Assuming you have the We.Retail demo content on your instance, visiting http://localhost:4502/bin/demoServlet should show you the results of two queries: one with an ORDER BY clause and one without (in this case, the name is the name of the page, ie: the leaf node name for each result):