Skip to content

Commit

Permalink
Implement missing prepareSeekExact methods for TermsEnum
Browse files Browse the repository at this point in the history
In apache/lucene#13359 a new "prepareSeekExact" method
was added that can improve seeking on TermsEnum implementations. Two of our own
subclasses of TermsEnum don't seem to support seeking for text, so we can safely
throw an UOE there. The third (FilterableTermsEnum) changes to simple returning
a Supplier for the actual "seek" method for now.
  • Loading branch information
cbuescher committed Aug 28, 2024
1 parent 919e906 commit 0d67210
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.lucene.util.BitSet;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.IOBooleanSupplier;
import org.elasticsearch.core.Nullable;

import java.io.IOException;
Expand Down Expand Up @@ -61,7 +62,7 @@ static class Holder {
protected BytesRef current;
protected final int docsEnumFlag;

public FilterableTermsEnum(IndexReader reader, String field, int docsEnumFlag, @Nullable Query filter) throws IOException {
public FilterableTermsEnum(IndexReader reader, String field, int docsEnumFlag, @Nullable Query f) throws IOException {
if ((docsEnumFlag != PostingsEnum.FREQS) && (docsEnumFlag != PostingsEnum.NONE)) {
throw new IllegalArgumentException("invalid docsEnumFlag of " + docsEnumFlag);
}
Expand Down Expand Up @@ -176,6 +177,11 @@ public boolean seekExact(BytesRef text) throws IOException {
}
}

@Override
public IOBooleanSupplier prepareSeekExact(BytesRef bytesRef) {
return () -> this.seekExact(bytesRef);

This comment has been minimized.

Copy link
@cbuescher

cbuescher Aug 28, 2024

Author Member

@jpountz I took this from BaseTermsEnum, I don't know if this can be done differently so far. This implementation seems to wrap a number of TermsEnum/Bitset pairs that are create in its contructor, and "seek" later loops over them. I don't know enough about your change in Lucene to decide whether also looping over those inner enums and call "prepareSeekExact" would be the better option here.

This comment has been minimized.

Copy link
@jpountz

jpountz Aug 28, 2024

Contributor

We may want to better take advantage of prepareSeekExact later on but this is correct this way and would perform like today.

}

@Override
public int docFreq() throws IOException {
return currentDocFreq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.lucene.search.SortField;
import org.apache.lucene.util.AttributeSource;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.IOBooleanSupplier;
import org.apache.lucene.util.automaton.Automata;
import org.apache.lucene.util.automaton.Automaton;
import org.apache.lucene.util.automaton.CompiledAutomaton;
Expand Down Expand Up @@ -459,6 +460,11 @@ public AttributeSource attributes() {
throw new UnsupportedOperationException();
}

@Override
public IOBooleanSupplier prepareSeekExact(BytesRef bytesRef) throws IOException {
throw new UnsupportedOperationException();
}

@Override
public boolean seekExact(BytesRef text) throws IOException {
throw new UnsupportedOperationException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.util.AttributeSource;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.IOBooleanSupplier;
import org.elasticsearch.index.mapper.MappedFieldType;

import java.io.IOException;
Expand Down Expand Up @@ -69,6 +70,11 @@ public AttributeSource attributes() {
throw new UnsupportedOperationException();
}

@Override
public IOBooleanSupplier prepareSeekExact(BytesRef bytesRef) throws IOException {
throw new UnsupportedOperationException();
}

@Override
public boolean seekExact(BytesRef text) throws IOException {
throw new UnsupportedOperationException();
Expand Down

0 comments on commit 0d67210

Please sign in to comment.