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/22 10:54:42 UTC
(solr) branch jira/solr-13350 updated: factor out SearchResult.getMaxScore 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
The following commit(s) were added to refs/heads/jira/solr-13350 by this push:
new 5d9ba11101e factor out SearchResult.getMaxScore method
5d9ba11101e is described below
commit 5d9ba11101ed23a2026bb35550f747f40c9fee88
Author: Christine Poerschke <cp...@apache.org>
AuthorDate: Thu Feb 22 10:54:06 2024 +0000
factor out SearchResult.getMaxScore method
---
.../org/apache/solr/search/SolrIndexSearcher.java | 27 +++++++++++++---------
1 file changed, 16 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 77ab59f124b..8e212ea7b4a 100644
--- a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
+++ b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
@@ -1940,12 +1940,7 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable, SolrI
totalHits = result.totalHits;
topDocs = result.topDocs;
- if (res.length > 1) {
- MaxScoreResult result2 = (MaxScoreResult) res[1];
- maxScore = totalHits > 0 ? result2.maxScore : 0.0f;
- } else {
- maxScore = Float.NaN;
- }
+ maxScore = searchResult.getMaxScore(totalHits);
}
hitsRelation = populateScoresIfNeeded(cmd, needScores, topDocs, query, scoreModeUsed);
@@ -2172,6 +2167,19 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable, SolrI
this.scoreMode = scoreMode;
this.result = result;
}
+
+ public float getMaxScore(int totalHits) {
+ if (totalHits > 0) {
+ for (Object res : result) {
+ if (res instanceof MaxScoreResult) {
+ return ((MaxScoreResult) res).maxScore;
+ }
+ }
+ return Float.NaN;
+ } else {
+ return 0.0f;
+ }
+ }
}
// any DocSet returned is for the query only, without any filtering... that way it may
@@ -2183,7 +2191,7 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable, SolrI
final int lastDocRequested = last;
final int nDocsReturned;
final int totalHits;
- float maxScore = Float.NaN;
+ final float maxScore;
final int[] ids;
final float[] scores;
DocSet set = null;
@@ -2280,11 +2288,8 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable, SolrI
TopDocsResult result = (TopDocsResult) res[0];
totalHits = result.totalHits;
topDocs = result.topDocs;
+ maxScore = searchResult.getMaxScore(totalHits);
if (needMaxScore) {
- if (res.length > 1) {
- MaxScoreResult result2 = (MaxScoreResult) res[1];
- maxScore = totalHits > 0 ? result2.maxScore : 0.0f;
- }
if (res.length > 2) {
DocSetResult result3 = (DocSetResult) res[2];
set = result3.docSet;