'Does Liferay's search always return results in the same order?

I got the bug report from a client that items on a page are displayed in random order, that is, that positions of elements on page change upon each refresh of a page.

Upon further investigation, I have found nothing in our code that can randomly position elements. Elements are allways fetched and processed during rendering phase in the same order.

So, I started to suspect on Liferay. We use Liferay and its Web content to create a structure and a new instance of this structure where we input data. Then that data is stored in the Liferay's database and when page is rendered we are fetching that data from database using Liferay's search. Here is the line where we perform searching: indexSearcherHelper.search(searchContext, query);. We than process search results one by one and render them on page.

So, as far as I can think of, only place where results may get randomized is this search method.

I know that search can be configured and that by changing configuration an order may change. And also, I can think of a situation when we add more data, that the order may change as well.

But this is running application, nothing is changed, no data is added and yet, it appears that results are not returned in the same order.

Unfortunately, I can not reproduce the problem at development environment, for me, results are allways returned in the same order. But on production environment, they mostly are, except in some rare cases when they are not.

So my question is, can Liferay's search method be the cause of this behaviour? Or, rephrased question: Are multiple consequitive invocations of the search method guaranteed to return results in the same order?



Solution 1:[1]

Yes, It will return data in the same order.It will change when you change the query (boolean query and main query).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Avinash