jpountz commented on code in PR #12383:
URL: https://github.com/apache/lucene/pull/12383#discussion_r1241088499


##########
lucene/core/src/java/org/apache/lucene/search/TermQuery.java:
##########
@@ -72,7 +72,16 @@ public TermWeight(
       if (termStats == null) {
         this.simScorer = null; // term doesn't exist in any segment, we won't 
use similarity at all
       } else {
-        this.simScorer = similarity.scorer(boost, collectionStats, termStats);
+        if (scoreMode.needsScores()) {

Review Comment:
   Can you add a comment about why this case is getting optimized? At first 
sight it could be surprising that we optimize the `simScorer` when scores are 
not needed since it's not expected to be called.



##########
lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionScoreQuery.java:
##########
@@ -322,6 +329,19 @@ private void assertInnerScoreMode(
       ScoreMode expectedScoreMode, ScoreMode inputScoreMode, 
DoubleValuesSource valueSource)
       throws IOException {
     final AtomicReference<ScoreMode> scoreModeInWeight = new 
AtomicReference<ScoreMode>();
+    final AtomicBoolean scorerCalled = new AtomicBoolean();

Review Comment:
   This test doesn't feel like it belongs to `TestFunctionQuery`, it should be 
in a test case for term queries instead?



##########
lucene/core/src/java/org/apache/lucene/search/TermQuery.java:
##########
@@ -72,7 +72,16 @@ public TermWeight(
       if (termStats == null) {
         this.simScorer = null; // term doesn't exist in any segment, we won't 
use similarity at all
       } else {
-        this.simScorer = similarity.scorer(boost, collectionStats, termStats);
+        if (scoreMode.needsScores()) {
+          this.simScorer = similarity.scorer(boost, collectionStats, 
termStats);
+        } else {
+          this.simScorer = new Similarity.SimScorer() {
+            @Override
+            public float score(float freq, long norm) {
+              return 0f;

Review Comment:
   Or throw an exception? It shouldn't get called, `AssertingScorer` already 
checks this iirc.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to