You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2020/03/13 17:23:28 UTC

[GitHub] [lucene-solr] micpalmia commented on a change in pull request #1343: LUCENE-8103: Use two-phase iteration in Query- and DoubleValuesSource

micpalmia commented on a change in pull request #1343: LUCENE-8103: Use two-phase iteration in Query- and DoubleValuesSource
URL: https://github.com/apache/lucene-solr/pull/1343#discussion_r392367810
 
 

 ##########
 File path: lucene/core/src/java/org/apache/lucene/search/DoubleValuesSource.java
 ##########
 @@ -604,18 +604,26 @@ public DoubleValues getValues(LeafReaderContext ctx, DoubleValues scores) throws
       Scorer scorer = weight.scorer(ctx);
       if (scorer == null)
         return DoubleValues.EMPTY;
-      DocIdSetIterator it = scorer.iterator();
+
       return new DoubleValues() {
+        private final TwoPhaseIterator tpi = scorer.twoPhaseIterator();
+        private final DocIdSetIterator disi = (tpi == null) ? scorer.iterator() : tpi.approximation();
+
+        private int scorerDoc = -1;
+        private boolean thisDocMatches = false;
+
         @Override
         public double doubleValue() throws IOException {
-          return scorer.score();
+          return thisDocMatches ? scorer.score() : Double.NaN;
         }
 
         @Override
         public boolean advanceExact(int doc) throws IOException {
-          if (it.docID() > doc)
-            return false;
-          return it.docID() == doc || it.advance(doc) == doc;
+          if (scorerDoc < doc) {
+            scorerDoc = disi.advance(doc);
+            thisDocMatches = tpi==null || tpi.matches();
 
 Review comment:
   I've done as you suggested. I'm a bit concerned about the performance implications of the unboxing though - this implementation is transforming a Boolean to a boolean for every matching document. I can look at running performance tests if you think that would be important.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

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