From ad01a67c5193329c0cd74ef5b304aad99edfa1ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Wed, 12 Jul 2017 10:01:18 +0200 Subject: [PATCH] Remove SearchHit#internalHits (#25653) This method does exactly what getHits() does and is used in only a few places, so it can safely be removed. It seems to be a left-over from when InternalSearchHits was folded into the SearchHits interface, which didn't contain this method. --- .../action/search/SearchPhaseController.java | 13 +++++++------ .../java/org/elasticsearch/search/SearchHits.java | 4 ---- .../metrics/tophits/TopHitsAggregator.java | 6 +++--- .../fetch/subphase/InnerHitsFetchSubPhase.java | 2 +- .../action/search/FetchSearchPhaseTests.java | 2 +- .../metrics/tophits/InternalTopHitsTests.java | 4 ++-- 6 files changed, 14 insertions(+), 17 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/search/SearchPhaseController.java b/core/src/main/java/org/elasticsearch/action/search/SearchPhaseController.java index 879607d059e80..6149bd9db34d6 100644 --- a/core/src/main/java/org/elasticsearch/action/search/SearchPhaseController.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchPhaseController.java @@ -21,6 +21,7 @@ import com.carrotsearch.hppc.IntArrayList; import com.carrotsearch.hppc.ObjectObjectHashMap; + import org.apache.lucene.index.Term; import org.apache.lucene.search.CollectionStatistics; import org.apache.lucene.search.FieldDoc; @@ -329,9 +330,9 @@ public InternalSearchResponse merge(boolean ignoreFrom, ReducedQueryPhase reduce } FetchSearchResult fetchResult = searchResultProvider.fetchResult(); final int index = fetchResult.counterGetAndIncrement(); - assert index < fetchResult.hits().internalHits().length : "not enough hits fetched. index [" + index + "] length: " - + fetchResult.hits().internalHits().length; - SearchHit hit = fetchResult.hits().internalHits()[index]; + assert index < fetchResult.hits().getHits().length : "not enough hits fetched. index [" + index + "] length: " + + fetchResult.hits().getHits().length; + SearchHit hit = fetchResult.hits().getHits()[index]; CompletionSuggestion.Entry.Option suggestOption = suggestionOptions.get(scoreDocIndex - currentOffset); hit.score(shardDoc.score); @@ -381,9 +382,9 @@ private SearchHits getHits(ReducedQueryPhase reducedQueryPhase, boolean ignoreFr } FetchSearchResult fetchResult = fetchResultProvider.fetchResult(); final int index = fetchResult.counterGetAndIncrement(); - assert index < fetchResult.hits().internalHits().length : "not enough hits fetched. index [" + index + "] length: " - + fetchResult.hits().internalHits().length; - SearchHit searchHit = fetchResult.hits().internalHits()[index]; + assert index < fetchResult.hits().getHits().length : "not enough hits fetched. index [" + index + "] length: " + + fetchResult.hits().getHits().length; + SearchHit searchHit = fetchResult.hits().getHits()[index]; searchHit.score(shardDoc.score); searchHit.shard(fetchResult.getSearchShardTarget()); if (sorted) { diff --git a/core/src/main/java/org/elasticsearch/search/SearchHits.java b/core/src/main/java/org/elasticsearch/search/SearchHits.java index aef585ca2a257..cc1aae7973673 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchHits.java +++ b/core/src/main/java/org/elasticsearch/search/SearchHits.java @@ -95,10 +95,6 @@ public Iterator iterator() { return Arrays.stream(getHits()).iterator(); } - public SearchHit[] internalHits() { - return this.hits; - } - public static final class Fields { public static final String HITS = "hits"; public static final String TOTAL = "total"; diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregator.java index 6b8e44133575a..e26cf00671f2d 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregator.java @@ -33,6 +33,8 @@ import org.elasticsearch.common.lease.Releasables; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.util.LongObjectPagedHashMap; +import org.elasticsearch.search.SearchHit; +import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.LeafBucketCollector; @@ -41,8 +43,6 @@ import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.fetch.FetchPhase; import org.elasticsearch.search.fetch.FetchSearchResult; -import org.elasticsearch.search.SearchHit; -import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.search.internal.SubSearchContext; import org.elasticsearch.search.rescore.RescoreSearchContext; @@ -165,7 +165,7 @@ public InternalAggregation buildAggregation(long owningBucketOrdinal) { subSearchContext.docIdsToLoad(docIdsToLoad, 0, docIdsToLoad.length); fetchPhase.execute(subSearchContext); FetchSearchResult fetchResult = subSearchContext.fetchResult(); - SearchHit[] internalHits = fetchResult.fetchResult().hits().internalHits(); + SearchHit[] internalHits = fetchResult.fetchResult().hits().getHits(); for (int i = 0; i < internalHits.length; i++) { ScoreDoc scoreDoc = topDocs.scoreDocs[i]; SearchHit searchHitFields = internalHits[i]; diff --git a/core/src/main/java/org/elasticsearch/search/fetch/subphase/InnerHitsFetchSubPhase.java b/core/src/main/java/org/elasticsearch/search/fetch/subphase/InnerHitsFetchSubPhase.java index d1fd74eaa7b86..a0a1d60666eee 100644 --- a/core/src/main/java/org/elasticsearch/search/fetch/subphase/InnerHitsFetchSubPhase.java +++ b/core/src/main/java/org/elasticsearch/search/fetch/subphase/InnerHitsFetchSubPhase.java @@ -66,7 +66,7 @@ public void hitsExecute(SearchContext context, SearchHit[] hits) throws IOExcept innerHits.docIdsToLoad(docIdsToLoad, 0, docIdsToLoad.length); fetchPhase.execute(innerHits); FetchSearchResult fetchResult = innerHits.fetchResult(); - SearchHit[] internalHits = fetchResult.fetchResult().hits().internalHits(); + SearchHit[] internalHits = fetchResult.fetchResult().hits().getHits(); for (int j = 0; j < internalHits.length; j++) { ScoreDoc scoreDoc = topDoc.scoreDocs[j]; SearchHit searchHitFields = internalHits[j]; diff --git a/core/src/test/java/org/elasticsearch/action/search/FetchSearchPhaseTests.java b/core/src/test/java/org/elasticsearch/action/search/FetchSearchPhaseTests.java index 3f940c54e62b3..c50ea270978c3 100644 --- a/core/src/test/java/org/elasticsearch/action/search/FetchSearchPhaseTests.java +++ b/core/src/test/java/org/elasticsearch/action/search/FetchSearchPhaseTests.java @@ -350,7 +350,7 @@ public void run() throws IOException { mockSearchPhaseContext.assertNoFailure(); assertNotNull(responseRef.get()); assertEquals(2, responseRef.get().getHits().totalHits); - assertEquals(1, responseRef.get().getHits().internalHits().length); + assertEquals(1, responseRef.get().getHits().getHits().length); assertEquals(84, responseRef.get().getHits().getAt(0).docId()); assertEquals(0, responseRef.get().getFailedShards()); assertEquals(2, responseRef.get().getSuccessfulShards()); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/tophits/InternalTopHitsTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/tophits/InternalTopHitsTests.java index cfec0d6aaee5a..a4cd82eeadb0b 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/tophits/InternalTopHitsTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/tophits/InternalTopHitsTests.java @@ -178,14 +178,14 @@ protected void assertReduced(InternalTopHits reduced, List inpu SearchHits internalHits = inputs.get(input).getHits(); totalHits += internalHits.getTotalHits(); maxScore = max(maxScore, internalHits.getMaxScore()); - for (int i = 0; i < internalHits.internalHits().length; i++) { + for (int i = 0; i < internalHits.getHits().length; i++) { ScoreDoc doc = inputs.get(input).getTopDocs().scoreDocs[i]; if (testInstancesLookSortedByField) { doc = new FieldDoc(doc.doc, doc.score, ((FieldDoc) doc).fields, input); } else { doc = new ScoreDoc(doc.doc, doc.score, input); } - allHits.add(new Tuple<>(doc, internalHits.internalHits()[i])); + allHits.add(new Tuple<>(doc, internalHits.getHits()[i])); } } allHits.sort(comparing(Tuple::v1, scoreDocComparator()));