You can use the atg.repository.QueryOptions class to specify ways that a query can be modified. You can set the QueryOptions properties, and pass the QueryOptions bean to the following executeQuery method:
RepositoryItem[] executeQuery(Query pQuery, QueryOptions pQueryOptions);
The QueryOptions properties let you limit the size of the result set, direct how the result set should be sorted, and precache specified properties:
| Property Name | Description | 
|---|---|
| 
 | The index of the first element of a query result set that should actually be returned. By setting  | 
| 
 | The items beginning with the  | 
| 
 | Specifies the sort order of a query’s result set. | 
| 
 | A list of properties that should be precached for each item in a query’s result set at the time the query is run. | 
The following example contains the following steps:
- Creates an unconstrained query against the Profile Repository. 
- Creates a - SortDirectivesthat contains a- SortDirective, sorting the result set in ascending order by the login property. A- SortDirectivecan be ascending or descending and case-sensitive or case-insensitive (although not all data stores support case-insensitive sorting).
- Creates a - QueryOptionswith a- startingIndexof 0 and an- endingIndexof 5. This limits the number of profiles returned to at most 5. The- QueryOptionsincorporates the- SortDirectives.
- Executes the query with the - QueryOptions.
- Outputs the results, displaying the - loginproperty.
// Creates an unconstrained query against the profile repository.
// It returns at most the first 5 profiles.
// Hints are used to precache login and password properties.
// Results are sorted by the login property.
Repository repository = (Repository)request.resolveName(
  "/atg/userprofiling/ProfileAdapterRepository");
RepositoryView view = repository.getView("user");
Query query = view.getQueryBuilder().createUnconstrainedQuery();
String [] precachedPropertyNames = {"login", "password"};
SortDirectives sortDirectives = new SortDirectives();
sortDirectives.addDirective(new SortDirective(
  "login",SortDirective.DIR_ASCENDING));
RepositoryItem [] items = view.executeQuery(
  query, new QueryOptions(0, 5, sortDirectives, precachedPropertyNames));
for (int i = 0; i < items.length; i++)
  out.print("<li>" + items[i].getPropertyValue("login"));
