Apache Lucene open-source search software
SOLR-9543: reduce code duplication in ReRankQParserPlugin.ReRankCollector.topDocs (part 1 of 2)
Christine Poerschkea9eb64e427a6
diff --git a/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.javaindex 2c462a0aae5..e4f00ee7384 100644--- a/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java+++ b/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java@@ -246,6 +246,18 @@ public class ReRankQParserPlugin extends QParserPlugin {return mainDocs;}+ ScoreDoc[] mainScoreDocs = mainDocs.scoreDocs;+ ScoreDoc[] reRankScoreDocs = new ScoreDoc[Math.min(mainScoreDocs.length, reRankDocs)];+ System.arraycopy(mainScoreDocs, 0, reRankScoreDocs, 0, reRankScoreDocs.length);++ mainDocs.scoreDocs = reRankScoreDocs;++ TopDocs rescoredDocs = reRankQueryRescorer+ .rescore(searcher, mainDocs, mainDocs.scoreDocs.length);++ //Lower howMany to return if we've collected fewer documents.+ howMany = Math.min(howMany, mainScoreDocs.length);+if(boostedPriority != null) {SolrRequestInfo info = SolrRequestInfo.getRequestInfo();Map requestContext = null;@@ -255,20 +267,8 @@ public class ReRankQParserPlugin extends QParserPlugin {IntIntHashMap boostedDocs = QueryElevationComponent.getBoostDocs((SolrIndexSearcher)searcher, boostedPriority, requestContext);- ScoreDoc[] mainScoreDocs = mainDocs.scoreDocs;- ScoreDoc[] reRankScoreDocs = new ScoreDoc[Math.min(mainScoreDocs.length, reRankDocs)];- System.arraycopy(mainScoreDocs,0,reRankScoreDocs,0,reRankScoreDocs.length);-- mainDocs.scoreDocs = reRankScoreDocs;-- TopDocs rescoredDocs = reRankQueryRescorer- .rescore(searcher, mainDocs, mainDocs.scoreDocs.length);-Arrays.sort(rescoredDocs.scoreDocs, new BoostedComp(boostedDocs, mainDocs.scoreDocs, rescoredDocs.getMaxScore()));- //Lower howMany if we've collected fewer documents.- howMany = Math.min(howMany, mainScoreDocs.length);-if(howMany == rescoredDocs.scoreDocs.length) {return rescoredDocs; // Just return the rescoredDocs} else if(howMany > rescoredDocs.scoreDocs.length) {@@ -288,26 +288,6 @@ public class ReRankQParserPlugin extends QParserPlugin {} else {- ScoreDoc[] mainScoreDocs = mainDocs.scoreDocs;-- /*- * Create the array for the reRankScoreDocs.- */- ScoreDoc[] reRankScoreDocs = new ScoreDoc[Math.min(mainScoreDocs.length, reRankDocs)];-- /*- * Copy the initial results into the reRankScoreDocs array.- */- System.arraycopy(mainScoreDocs, 0, reRankScoreDocs, 0, reRankScoreDocs.length);-- mainDocs.scoreDocs = reRankScoreDocs;-- TopDocs rescoredDocs = reRankQueryRescorer- .rescore(searcher, mainDocs, mainDocs.scoreDocs.length);-- //Lower howMany to return if we've collected fewer documents.- howMany = Math.min(howMany, mainScoreDocs.length);-if(howMany == rescoredDocs.scoreDocs.length) {return rescoredDocs; // Just return the rescoredDocs} else if(howMany > rescoredDocs.scoreDocs.length) {