Limiting and paginating query results

When you execute a query, you can limit results by retrieving only the first N results, retrieving N results starting from the Mth result, or retrieving all results starting from the Nth result (where N and M are numbers you specify).

You can limit the number of results returned using the SetResultFilter (ASP.NET) or setResultFilter (JSP) method in the Query class. The SetResultFilter (ASP.NET) or setResultFilter method takes an object that implements the ResultFilter interface. There are two classes that implement this interface: LimitFilter and PagingFilter.

LimitFilter
Use this filter to retrieve only the first N results. The constructor for this class takes one integer as parameter.
PagingFilter

Use this filter, which takes two integers as parameters, for the following scenarios:

  • to retrieve N results, starting from the Mth result: set the first parameter to M - 1 (the results are zero-based), and the second parameter to N (the number of results you want to retrieve).
  • to retrieve all results, starting rom the Mth result: set the first parameter to M - 1, and the second parameter to -1.

For example, the following Paging Filter retrieves the 6th, 7th and 8th results (JSP example):

PagingFilter filter = new PagingFilter(5, 3)

The following Paging Filter retrieves all results, starting from the 6th result (JSP example):

PagingFilter filter = new PagingFilter(5, -1)

You can execute queries repeatedly, using the PagingFilter object to paginate your results into fixed sets of results.