Skip to content

Commit

Permalink
HSEARCH-4939 Avoid uses of Lucene's NO_MORE_ORDS constant
Browse files Browse the repository at this point in the history
  • Loading branch information
marko-bekhta committed Sep 5, 2023
1 parent 267fb09 commit 077ac00
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static JoiningTextMultiValuesSource fromField(String field, NestedDocsPro

protected final NestedDocsProvider nestedDocsProvider;

public JoiningTextMultiValuesSource(NestedDocsProvider nestedDocsProvider) {
protected JoiningTextMultiValuesSource(NestedDocsProvider nestedDocsProvider) {
this.nestedDocsProvider = nestedDocsProvider;
}

Expand Down Expand Up @@ -84,15 +84,12 @@ public boolean advanceExact(int parentDoc) throws IOException {
return hasNextValue();
}

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

return childDocsWithValues.advanceExactParent( parentDoc );
}

@Override
public boolean hasNextValue() throws IOException {
if ( nextOrd != NO_MORE_ORDS ) {
if ( super.hasNextValue() ) {
return true;
}

Expand All @@ -101,7 +98,6 @@ public boolean hasNextValue() throws IOException {
return true;
}
else {
nextOrd = NO_MORE_ORDS;
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
*/
public abstract class TextMultiValues {

protected static final long NO_MORE_ORDS = -1L;

/**
* Sole constructor. (For invocation by subclass
* constructors, typically implicit.)
Expand Down Expand Up @@ -91,6 +89,8 @@ protected static class DocValuesTextMultiValues extends TextMultiValues {

protected final SortedSetDocValues values;
protected long nextOrd;
protected int docValueCount = 0;
protected int nextOrdIndex = 0;

DocValuesTextMultiValues(SortedSetDocValues values) {
this.values = values;
Expand All @@ -99,20 +99,28 @@ protected static class DocValuesTextMultiValues extends TextMultiValues {
@Override
public boolean advanceExact(int doc) throws IOException {
boolean found = values.advanceExact( doc );
nextOrd = found ? values.nextOrd() : NO_MORE_ORDS;
if ( found ) {
nextOrd = values.nextOrd();
docValueCount = values.docValueCount();
}
else {
docValueCount = 0;
}
nextOrdIndex = 0;
return found;
}

@Override
public boolean hasNextValue() throws IOException {
return nextOrd != NO_MORE_ORDS;
return nextOrdIndex < docValueCount;
}

@Override
public long nextOrd() throws IOException {
long result = nextOrd;
nextOrdIndex++;
long previousOrd = nextOrd;
nextOrd = values.nextOrd();
return result;
return previousOrd;
}

@Override
Expand Down

0 comments on commit 077ac00

Please sign in to comment.