Use search parameters to control the search, such as the page size and the sort order of the search results. To control your search, use the search() method that accepts the SearchParameters class.
As you create the code for searching, use the search parameter constructors. The constructors include a combination of the following search parameters:
•beginIndex—The first page of results the search returns.
•limit—The number of search results to return on a page.
•useUnsavedChanges—An indication of whether the search should run against changes not yet committed to the database.
•sortFields—The fields for sorting the search results.
If a constructor does not include one of these parameters, the search uses the default for the parameter. Retrieve or set the default settings using the SearchParameters get and set methods (getBeginIndex(), setLimit(), etc.).
The following list provides examples of some SearchParameters constructors. For a full list of constructors, refer to the SearchParameters class in the javadocs.
•SearchParameters(SortField... sortFields)
You can specify how you want the search results to sort. This constructor creates a parameter with one or more sort fields, the default limit, and the default begin index. The following code sample sorts the results by start date in ascending order.
// Sort results by start date SearchParameters parameters = new SearchParameters(new SortField(Appointment.START_ON)); |
•SearchParameters(java.lang.Integer limit)
You can limit the number of results in a search. This constructor creates a parameter with the number of search results, the default being index, and no sort fields. The following code sample limits the number of results to 10 records.
// Limit results to 10 records SearchParameters parameters = new SearchParameters(10); |
•SearchParameters(boolean useUnsavedChanges)
You can specify whether a search should return results from the database or changes not yet commented to the database. This constructor creates a parameter that specifies which to search, the default limit and begin index, and no sort fields. The following code sample specifies that the search results will include changes not yet saved to the database.
// Includes unsaved changes in search results SearchParameters parameters = new SearchParameters(true); |