You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by cp...@apache.org on 2024/02/19 16:16:03 UTC

(solr) 01/02: factor out SolrIndexSearcher.populateScoresIfNeeded method

This is an automated email from the ASF dual-hosted git repository.

cpoerschke pushed a commit to branch jira/solr-13350
in repository https://gitbox.apache.org/repos/asf/solr.git

commit 2201a7d7526b3c39e135e06abfdf22e6b2cd6b45
Author: Christine Poerschke <cp...@apache.org>
AuthorDate: Mon Feb 19 16:04:42 2024 +0000

    factor out SolrIndexSearcher.populateScoresIfNeeded method
---
 .../org/apache/solr/search/SolrIndexSearcher.java  | 26 +++++++++++++---------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
index 5db23a5d391..a7c9712c348 100644
--- a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
+++ b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
@@ -1738,6 +1738,19 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable, SolrI
     }
   }
 
+  private Relation populateScoresIfNeeded(
+      QueryCommand cmd, boolean needScores, TopDocs topDocs, Query query, ScoreMode scoreModeUsed)
+      throws IOException {
+    if (cmd.getSort() != null && !(cmd.getQuery() instanceof RankQuery) && needScores) {
+      TopFieldCollector.populateScores(topDocs.scoreDocs, this, query);
+    }
+    if (scoreModeUsed == ScoreMode.COMPLETE || scoreModeUsed == ScoreMode.COMPLETE_NO_SCORES) {
+      return TotalHits.Relation.EQUAL_TO;
+    } else {
+      return topDocs.totalHits.relation;
+    }
+  }
+
   /**
    * Helper method for extracting the {@link FieldDoc} sort values from a {@link TopFieldDocs} when
    * available and making the appropriate call to {@link QueryResult#setNextCursorMark} when
@@ -1901,14 +1914,7 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable, SolrI
 
         totalHits = topCollector.getTotalHits();
         topDocs = topCollector.topDocs(0, len);
-        if (scoreModeUsed == ScoreMode.COMPLETE || scoreModeUsed == ScoreMode.COMPLETE_NO_SCORES) {
-          hitsRelation = TotalHits.Relation.EQUAL_TO;
-        } else {
-          hitsRelation = topDocs.totalHits.relation;
-        }
-        if (cmd.getSort() != null && cmd.getQuery() instanceof RankQuery == false && needScores) {
-          TopFieldCollector.populateScores(topDocs.scoreDocs, this, query);
-        }
+        hitsRelation = populateScoresIfNeeded(cmd, needScores, topDocs, query, scoreModeUsed);
         populateNextCursorMarkFromTopDocs(qr, cmd, topDocs);
 
         maxScore =
@@ -2253,9 +2259,7 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable, SolrI
         assert (totalHits == set.size()) || qr.isPartialResults();
 
         topDocs = topCollector.topDocs(0, len);
-        if (cmd.getSort() != null && !(cmd.getQuery() instanceof RankQuery) && needScores) {
-          TopFieldCollector.populateScores(topDocs.scoreDocs, this, query);
-        }
+        populateScoresIfNeeded(cmd, needScores, topDocs, query, ScoreMode.COMPLETE);
         populateNextCursorMarkFromTopDocs(qr, cmd, topDocs);
         maxScore =
             totalHits > 0