Hi, s.grinovero. Thank you for your interest.
In case of this snippet
Code:
final FullTextQuery ftQuery = fullTextSession.createFullTextQuery(luceneQuery, searchEntity);
int begin = page * (int) itemsPerPage;
Criteria criteria = session.createCriteria(searchEntity).setMaxResults(itemsPerPage).setFirstResult(begin);
...
ftQuery.setCriteriaQuery(criteria);
List<T> results = ftQuery.list();
Without ordering, I am getting this SQL query from hibernate (MySQL dialect used)
Code:
Hibernate: select ... where (this_.REALTY_MESSAGE_ID in (?, ?, ?, ?, ?, ?, ?)) limit ?
The paging of search results is working correct (e.g. when I am retrieving the next page LIMIT clause is changed to 5,10) and so forth.
As far as i understand, Lucene returns IDs in order by relevance (Lucene order) and list them in "in" clause of the query. So, i get the Lucene ordered result.
In the second case, with ordering, I am getting the query:
Code:
Hibernate: select ... where (this_.REALTY_MESSAGE_ID in (?, ?, ?, ?, ?, ?, ?)) order by this_.BEGIN_DATE asc limit ?
So, according to this query, i am getting the list of items which ids contained in the "IN" clause, then ordering is performed and then "LIMIT" clause truncated results. In this case I am getting results not ordered by Lucene, but included in Lucene index according to search query.
Then when I am retrieving next ordered page (e.g. ... order by this_.BEGIN_DATE asc limit 5, 10), I am getting the next page of results already ordered by BEGIN_DATE! Yes, these are not ordered by Lucene, but I am using it as alternative ordering of results by date, price, district and so.
The live example is the following.
The user is preforming search from the web page - Lucene ordered results are returned. User can paging these results.
Alternatively, user have links to order results by date, price and so on. Using these links, user is sorting result found by Lucene.
I have a full working result of this approach, but the project in development now. I am planing it in production at the end of the month. But this site will support only Russian language, to view working sample. By the way, the paging is working correct in my case.