Previous | Next | Trail Map | The Basics | Directory Operations

Count Limit

Sometimes, there are queries you know that might produce many answers, perhaps too many answers, and you would like to limit the number of answers that you get back. You can do this by using the count limit search control. By default, a search does not have a count limit, which means that it will return all the answers that it finds.

To set the count limit of a search, pass the number to the method SearchControls.setCountLimit()(in the API reference documentation).

This example sets the count limit to 1:

// Set search controls to limit count to 1
SearchControls ctls = new SearchControls();
ctls.setCountLimit(1);
After performing the search, if the program attempts to get more than the count limit number of results, a SizeLimitExceededException(in the API reference documentation) will be thrown. So if a program has set a count limit, it should differentiate this exception from other NamingExceptions(in the API reference documentation) or keep track of the count limit and not request more than that number of results.


Previous | Next | Trail Map | The Basics | Directory Operations