Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate Full text Search Pagination

I am using Hibernate Fulltext search. I am currently using:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-search</artifactId>
    <version>4.5.1.Final</version>
</dependency>

I am able to search all right. The question I have is this: How can I paginate my results? Is there any way I can get say 50 results first and then make calls when next page is requested for the next 50 results?

One way I'm thinking of would be to simply get the max ID and then start next search from Max+1 position, assuming ID's are generated in auto incremental order. But I think there must be more elegant approach.

like image 219
Abhishek Ranjan Avatar asked Jan 10 '23 18:01

Abhishek Ranjan


1 Answers

From the Hibernate search-query docs on pagination.

org.hibernate.Query fullTextQuery = 
    fullTextSession.createFullTextQuery( luceneQuery, Customer.class );
fullTextQuery.setFirstResult(15); //start from the 15th element
fullTextQuery.setMaxResults(10); //return 10 elements
like image 96
ug_ Avatar answered Jan 14 '23 21:01

ug_