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 also need the ability to grab the next page, and then the next page, and so on. So the setFirstResult
method tells Hibernate Search where to start.
For example, the preceding code snippet starts with the eleventh result item (the parameter is...