O'Reilly logo

Hibernate Search by Example by Steve Perkins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Pagination

When a search query returns a huge number of search results, it is usually not desirable (or perhaps even possible) to present them to the user all at once. A common solution is pagination, or displaying search results one "page" at a time.

A Hibernate Search FullTextQuery object has methods for making pagination easy:

…
hibernateQuery.setFirstResult(10);
hibernateQuery.setMaxResults(5);
List<App> apps = hibernateQuery.list();
…

The setMaxResults method declares the maximum size of the page. On the last line of the preceding code snippet, the apps list will contain no more than five App objects, even if the query has thousands of matches.

Of course, pagination wouldn't be very useful if the code always grabbed the first five results. We ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required