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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With