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(); …
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 ...