Skip to content

Commit

Permalink
HSEARCH-4969 Align the implementation of LongMultiValues on TextMulti…
Browse files Browse the repository at this point in the history
…Values

I'm not sure this fixes a bug, but it makes the code clearer IMO.
  • Loading branch information
yrodiere committed Sep 25, 2023
1 parent f8eb6be commit b7019b3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,43 +89,30 @@ protected LongMultiValues select(SortedNumericDocValues values, ChildDocIds chil
return LongMultiValues.EMPTY;
}

return new LongMultiValues() {
int currentParentDoc = -1;
int remainingValuesForChild = 0;
return new LongMultiValues.DocValuesLongMultiValues( values ) {
private int currentParentDoc = -1;

@Override
public boolean advanceExact(int parentDoc) throws IOException {
assert parentDoc >= currentParentDoc : "can only evaluate current and upcoming parent docs";
if ( parentDoc == currentParentDoc ) {
return hasNextValue();
}

currentParentDoc = parentDoc;
remainingValuesForChild = 0; // To be set in the next call to hasNextValue()

return childDocsWithValues.advanceExactParent( parentDoc );
boolean found = childDocsWithValues.advanceExactParent( parentDoc );
updateRemaining( found );
return found;
}

@Override
public boolean hasNextValue() throws IOException {
if ( remainingValuesForChild > 0 ) {
return true;
}

if ( childDocsWithValues.nextChild() != DocIdSetIterator.NO_MORE_DOCS ) {
remainingValuesForChild = values.docValueCount();
if ( super.hasNextValue() ) {
return true;
}
else {
remainingValuesForChild = 0;
return false;
}
}

@Override
public long nextValue() throws IOException {
--remainingValuesForChild;
return values.nextValue();
boolean hasNextChildDocWithValue = childDocsWithValues.nextChild() != DocIdSetIterator.NO_MORE_DOCS;
updateRemaining( hasNextChildDocWithValue );
return hasNextChildDocWithValue;
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public long nextValue() {
}
};

private static class DocValuesLongMultiValues extends LongMultiValues {
protected static class DocValuesLongMultiValues extends LongMultiValues {

private final SortedNumericDocValues values;
private int remaining;
Expand All @@ -77,12 +77,16 @@ private static class DocValuesLongMultiValues extends LongMultiValues {
@Override
public boolean advanceExact(int doc) throws IOException {
boolean found = values.advanceExact( doc );
this.remaining = found ? values.docValueCount() : 0;
updateRemaining( found );
return found;
}

protected final void updateRemaining(boolean hasDocValue) {
remaining = hasDocValue ? values.docValueCount() : 0;
}

@Override
public boolean hasNextValue() {
public boolean hasNextValue() throws IOException {
return remaining > 0;
}

Expand Down

0 comments on commit b7019b3

Please sign in to comment.