Search in sources :

Example 6 with SearchProfileShardResults

use of org.opensearch.search.profile.SearchProfileShardResults in project OpenSearch by opensearch-project.

the class SearchResponseMergerTests method testMergeProfileResults.

public void testMergeProfileResults() throws InterruptedException {
    SearchTimeProvider searchTimeProvider = new SearchTimeProvider(0, 0, () -> 0);
    SearchResponseMerger merger = new SearchResponseMerger(0, 0, SearchContext.TRACK_TOTAL_HITS_ACCURATE, searchTimeProvider, emptyReduceContextBuilder());
    Map<String, ProfileShardResult> expectedProfile = new HashMap<>();
    for (int i = 0; i < numResponses; i++) {
        SearchProfileShardResults profile = SearchProfileShardResultsTests.createTestItem();
        expectedProfile.putAll(profile.getShardResults());
        SearchHits searchHits = new SearchHits(new SearchHit[0], new TotalHits(0, TotalHits.Relation.EQUAL_TO), Float.NaN);
        InternalSearchResponse internalSearchResponse = new InternalSearchResponse(searchHits, null, null, profile, false, null, 1);
        SearchResponse searchResponse = new SearchResponse(internalSearchResponse, null, 1, 1, 0, 100L, ShardSearchFailure.EMPTY_ARRAY, SearchResponse.Clusters.EMPTY);
        addResponse(merger, searchResponse);
    }
    awaitResponsesAdded();
    assertEquals(numResponses, merger.numResponses());
    SearchResponse.Clusters clusters = SearchResponseTests.randomClusters();
    SearchResponse mergedResponse = merger.getMergedResponse(clusters);
    assertSame(clusters, mergedResponse.getClusters());
    assertEquals(numResponses, mergedResponse.getTotalShards());
    assertEquals(numResponses, mergedResponse.getSuccessfulShards());
    assertEquals(0, mergedResponse.getSkippedShards());
    assertEquals(0, mergedResponse.getFailedShards());
    assertEquals(0, mergedResponse.getShardFailures().length);
    assertEquals(expectedProfile, mergedResponse.getProfileResults());
}
Also used : TotalHits(org.apache.lucene.search.TotalHits) SearchTimeProvider(org.opensearch.action.search.TransportSearchAction.SearchTimeProvider) HashMap(java.util.HashMap) InternalSearchResponse(org.opensearch.search.internal.InternalSearchResponse) SearchProfileShardResults(org.opensearch.search.profile.SearchProfileShardResults) SearchHits(org.opensearch.search.SearchHits) ProfileShardResult(org.opensearch.search.profile.ProfileShardResult) InternalSearchResponse(org.opensearch.search.internal.InternalSearchResponse)

Aggregations

SearchProfileShardResults (org.opensearch.search.profile.SearchProfileShardResults)6 InternalAggregations (org.opensearch.search.aggregations.InternalAggregations)5 InternalSearchResponse (org.opensearch.search.internal.InternalSearchResponse)5 SearchHits (org.opensearch.search.SearchHits)4 Suggest (org.opensearch.search.suggest.Suggest)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 TotalHits (org.apache.lucene.search.TotalHits)3 ProfileShardResult (org.opensearch.search.profile.ProfileShardResult)3 List (java.util.List)2 CompletionSuggestion (org.opensearch.search.suggest.completion.CompletionSuggestion)2 IntArrayList (com.carrotsearch.hppc.IntArrayList)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 TopDocs (org.apache.lucene.search.TopDocs)1 OriginalIndices (org.opensearch.action.OriginalIndices)1