*/
protected <S extends PagedRequest> void pagedSearch(SearchStrategy<D, M, S> searchStrategy, AbstractDocumentsResult<D> documentsResult, S searchRequest) {
//first, hive off the original paging request. this is
//because we're about to mutate the searchRequest so
//that it is appropriate for downstream masters.
PagingRequest originalPagingRequest = searchRequest.getPagingRequest();
//first page to request will be identical to passed
//page request.
PagingRequest nextPage = originalPagingRequest;
//totalResults used to keep track of whether we
//have accumulated enough records to satisfy the
//page size.
int totalResults = 0;
//iterate over the master list, stopping when we
//either run out of masters or the totalResults
//exceeds the range of records requested.
for (int i = 0; i < getMasterList().size(); i++) {
M master = getMasterList().get(i);
//delegate the query to the master via the strategy
AbstractDocumentsResult<D> masterResult = searchStrategy.search(master, searchRequest);
//totalItems() reflects the total number of records
//available from the queried master.
totalResults += masterResult.getPaging().getTotalItems();
documentsResult.getDocuments().addAll(masterResult.getDocuments());
if (i == getMasterList().size() - 1) {
//all masters are exhausted so stop here.
//totalResults will reflect the total number of
//records available across masters to no need
//to modify it (see next condition).
break;
}
if (totalResults >= nextPage.getLastItem()) {
//we have maxed out the requested window and more masters remain.
//add one to ensure that the gui makes further requests which will
//run into the next master's range.
totalResults += 1;
break;