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/20 18:00:12 UTC

(solr) branch branch_9x updated: factor out SolrIndexSearcher.populateScoresIfNeeded method (#2280)

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

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


The following commit(s) were added to refs/heads/branch_9x by this push:
     new 253fe384ca0 factor out SolrIndexSearcher.populateScoresIfNeeded method (#2280)
253fe384ca0 is described below

commit 253fe384ca010c86dd38b91c4ccb90cbc27010ca
Author: Christine Poerschke <cp...@apache.org>
AuthorDate: Tue Feb 20 16:59:34 2024 +0000

    factor out SolrIndexSearcher.populateScoresIfNeeded method (#2280)
    
    (cherry picked from commit 065d21abb42441568f6b505b896ffe26532a5bb5)
---
 .../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 2c7fe938561..35f34e30e1f 100644
--- a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
+++ b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
@@ -1743,6 +1743,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
@@ -1898,14 +1911,7 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable, SolrI
 
       totalHits = topCollector.getTotalHits();
       final TopDocs 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 =
@@ -2016,9 +2022,7 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable, SolrI
       assert (totalHits == set.size()) || qr.isPartialResults();
 
       final TopDocs 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