![]() ![]() ![]() ![]() |
Directory Operations |
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()
.
This example sets the count limit to 1:
After performing the search, if the program attempts to get more than the count limit number of results, a SizeLimitExceededException// Set search controls to limit count to 1 SearchControls ctls = new SearchControls(); ctls.setCountLimit(1);will be thrown. So if a program has set a count limit, it should differentiate this exception from other NamingExceptions
or keep track of the count limit and not request more than that number of results.
Specifying a count limit for a search is one way of controlling the resources (such as memory and network bandwidth) that your application consumes. The other ways are narrowing your search filter (by being more specific about what you are looking for), starting your search in the appropriate context, and using the appropriate scope.
![]() ![]() ![]() ![]() |
Directory Operations |