Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

factor out SolrIndexSearcher.populateScoresIfNeeded method (#2280)

Christine Poerschke065d21abb424
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 d2c42adbc12..e73a1554fa3 100644
--- a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
+++ b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
@@ -1731,6 +1731,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
@@ -1886,14 +1899,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 =
@@ -2004,9 +2010,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