Horatiu Lazu created LUCENE-8151:
------------------------------------

             Summary: Redundant conditionals in JoinUtil
                 Key: LUCENE-8151
                 URL: https://issues.apache.org/jira/browse/LUCENE-8151
             Project: Lucene - Core
          Issue Type: Improvement
            Reporter: Horatiu Lazu


JoinUtil has a strange conditional structure, which can be collapsed under one 
function call:

On line 200:
{code:java}
@Override
public void collect(int doc) throws IOException {
  if (doc > sortedNumericDocValues.docID()) {
    sortedNumericDocValues.advance(doc);
  }
  if (doc == sortedNumericDocValues.docID()) {
    for (int i = 0; i < sortedNumericDocValues.docValueCount(); i++) {
      long value = sortedNumericDocValues.nextValue();
      joinValues.add(value);
      if (needsScore) {
        scoreAggregator.accept(value, scorer.score());
      }
    }
  }
}{code}
Instead, just do advanceExact, which returns a boolean indicating if it was 
successful:
{code:java}
@Override
public void collect(int doc) throws IOException {
  if (sortedNumericDocValues.advanceExact(doc)) {
    for (int i = 0; i < sortedNumericDocValues.docValueCount(); i++) {
      long value = sortedNumericDocValues.nextValue();
      joinValues.add(value);
      if (needsScore) {
        scoreAggregator.accept(value, scorer.score());
      }
    }
  }
}

{code}
 I have the patch ready, it passes unit tests.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

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

Reply via email to