Set<String> idsLoaded = Sets.newHashSet();
ShardDoc[] sortedShardList = searchPhaseController.sortDocs(newArrayList(result));
Map<SearchShardTarget, QueryFetchSearchResult> queryResults = Maps.newHashMap();
queryResults.put(result.queryResult().shardTarget(), result);
InternalSearchResponse searchResponse = searchPhaseController.merge(sortedShardList, queryResults, queryResults);
for (SearchHit hit : searchResponse.hits()) {
idsLoaded.add(hit.id());
}
// iterate to the next 2
result = searchService.executeFetchPhase(searchRequest(searchSource().query(matchAllQuery()).from(2).size(2).sort("age", SortOrder.DESC), SearchType.QUERY_AND_FETCH));
assertThat(result.queryResult().topDocs().totalHits, equalTo(5));
sortedShardList = searchPhaseController.sortDocs(newArrayList(result));
queryResults = Maps.newHashMap();
queryResults.put(result.queryResult().shardTarget(), result);
searchResponse = searchPhaseController.merge(sortedShardList, queryResults, queryResults);
for (SearchHit hit : searchResponse.hits()) {
idsLoaded.add(hit.id());
}
result = searchService.executeFetchPhase(searchRequest(searchSource().query(matchAllQuery()).from(4).size(2).sort("age", SortOrder.DESC), SearchType.QUERY_AND_FETCH));
assertThat(result.queryResult().topDocs().totalHits, equalTo(5));
sortedShardList = searchPhaseController.sortDocs(newArrayList(result));
queryResults = Maps.newHashMap();
queryResults.put(result.queryResult().shardTarget(), result);
searchResponse = searchPhaseController.merge(sortedShardList, queryResults, queryResults);
for (SearchHit hit : searchResponse.hits()) {
idsLoaded.add(hit.id());
}
// verify all ids were loaded
Set<String> expectedIds = Sets.newHashSet("1", "2", "3", "4", "5");