Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Bug fixes:

API Changes

* LUCENE-8662: TermsEnum.seekExact(BytesRef) to abstract and delegate seekExact(BytesRef)
in FilterLeafReader.FilterTermsEnum. (Jeffery Yuan via Tomás Fernández Löbbe, Simon Willnauer)

* LUCENE-8469: Deprecated StringHelper.compare has been removed. (Dawid Weiss)

* LUCENE-8039: Introduce a "delta distance" method set to GeoDistance. This
Expand Down
7 changes: 7 additions & 0 deletions lucene/MIGRATE.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Apache Lucene Migration Guide

## TermsEnum.seekExact(BytesRef) is abstract (LUCENE-8662) ##

TermsEnum.seekExact has been changed to abstract, so non-abstract subclass must implement it.
The default implementation can be seekCeil(text) == SeekStatus.FOUND.
This method is performance critical, so subclass SHOULD have its own implementation
if possible instead of using the default implementation.

## RAMDirectory, RAMFile, RAMInputStream, RAMOutputStream removed ##

RAM-based directory implementation have been removed. (LUCENE-8474).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,11 @@ public BytesRef next() throws IOException {
return term;
}

@Override
public boolean seekExact(BytesRef text) throws IOException {
return seekCeil(text) == SeekStatus.FOUND;
}

@Override
public void seekExact(long ord) throws IOException {
if (ord < 0 || ord >= entry.termsDictSize) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,11 @@ public TermState termState() throws IOException {
return ts;
}

@Override
public boolean seekExact(BytesRef text) throws IOException {
return seekCeil(text) == SeekStatus.FOUND;
}

@Override
public void seekExact(long ord) throws IOException {
//System.out.println("BTR.seek by ord ord=" + ord);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,11 @@ public SeekStatus seekCeil(BytesRef term) {
public void seekExact(long ord) {
throw new UnsupportedOperationException();
}

@Override
public boolean seekExact(BytesRef text) throws IOException {
return seekCeil(text) == SeekStatus.FOUND;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,11 @@ void decodeStats() throws IOException {
super.decodeStats();
}

@Override
public boolean seekExact(BytesRef text) throws IOException {
return seekCeil(text) == SeekStatus.FOUND;
}

@Override
public SeekStatus seekCeil(BytesRef target) throws IOException {
throw new UnsupportedOperationException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,11 @@ void loadMetaData() throws IOException {
state.totalTermFreq = meta.totalTermFreq;
}

@Override
public boolean seekExact(BytesRef text) throws IOException {
return seekCeil(text) == SeekStatus.FOUND;
}

@Override
public SeekStatus seekCeil(BytesRef target) throws IOException {
decoded = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,11 @@ public SeekStatus seekCeil(BytesRef text) throws IOException {
}
}

@Override
public boolean seekExact(BytesRef text) throws IOException {
return seekCeil(text) == SeekStatus.FOUND;
}

@Override
public void seekExact(long ord) throws IOException {
throw new UnsupportedOperationException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,11 @@ public SeekStatus seekCeil(BytesRef text)
}
}

@Override
public boolean seekExact(BytesRef text) throws IOException {
return seekCeil(text) == SeekStatus.FOUND;
}

@Override
public void seekExact(long ord) throws IOException {
throw new UnsupportedOperationException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,11 @@ public BytesRef next() throws IOException {
return term;
}

@Override
public boolean seekExact(BytesRef text) throws IOException {
return seekCeil(text) == SeekStatus.FOUND;
}

@Override
public void seekExact(long ord) throws IOException {
if (ord < 0 || ord >= entry.termsDictSize) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ public AttributeSource attributes() {
public SeekStatus seekCeil(BytesRef text) throws IOException {
return in.seekCeil(text);
}

@Override
public boolean seekExact(BytesRef text) throws IOException {
return in.seekExact(text);
}

@Override
public void seekExact(long ord) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ public SeekStatus seekCeil(BytesRef text) {
}
}

@Override
public boolean seekExact(BytesRef text) throws IOException {
return seekCeil(text) == SeekStatus.FOUND;
}

public void seekExact(long ord) {
this.ord = (int) ord;
int textStart = postingsArray.textStarts[sortedTermIDs[this.ord]];
Expand Down
25 changes: 18 additions & 7 deletions lucene/core/src/java/org/apache/lucene/index/TermsEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,19 @@ public static enum SeekStatus {
NOT_FOUND
};

/** Attempts to seek to the exact term, returning
* true if the term is found. If this returns false, the
* enum is unpositioned. For some codecs, seekExact may
* be substantially faster than {@link #seekCeil}. */
public boolean seekExact(BytesRef text) throws IOException {
return seekCeil(text) == SeekStatus.FOUND;
}
/**
* Attempts to seek to the exact term, returning true if the term is found. If this returns false, the enum is
* unpositioned. For some codecs, seekExact may be substantially faster than {@link #seekCeil}.
* <p>
*
* The default implementation can be <code>seekCeil(text) == SeekStatus.FOUND; </code><br>
* But this method is performance critical. In some cases, the default implementation may be slow and consume huge memory,
* so subclass SHOULD have its own implementation if possible.
*
* @return true if the term is found; return false if the enum is unpositioned.
*/
public abstract boolean seekExact(BytesRef text) throws IOException;


/** Seeks to the specified term, if it exists, or to the
* next (ceiling) term. Returns SeekStatus to
Expand Down Expand Up @@ -206,6 +212,11 @@ public void copyFrom(TermState other) {
@Override
public SeekStatus seekCeil(BytesRef term) { return SeekStatus.END; }

@Override
public boolean seekExact(BytesRef text) throws IOException {
return seekCeil(text) == SeekStatus.FOUND;
}

@Override
public void seekExact(long ord) {}

Expand Down
5 changes: 5 additions & 0 deletions lucene/core/src/test/org/apache/lucene/index/TestCodecs.java
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,11 @@ public SeekStatus seekCeil(BytesRef text) {
return SeekStatus.END;
}

@Override
public boolean seekExact(BytesRef text) throws IOException {
return seekCeil(text) == SeekStatus.FOUND;
}

@Override
public void seekExact(long ord) {
throw new UnsupportedOperationException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,11 @@ public SeekStatus seekCeil(BytesRef term) {
}
}
}

@Override
public boolean seekExact(BytesRef text) throws IOException {
return seekCeil(text) == SeekStatus.FOUND;
}

@Override
public void seekExact(long ord) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,11 @@ public BytesRef next() {
}
}

@Override
public boolean seekExact(BytesRef text) throws IOException {
return seekCeil(text) == SeekStatus.FOUND;
}

@Override
public void seekExact(long ord) {
throw new UnsupportedOperationException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,11 @@ public SeekStatus seekCeil(BytesRef target) throws IOException {
}
}

@Override
public boolean seekExact(BytesRef text) throws IOException {
return seekCeil(text) == SeekStatus.FOUND;
}

@Override
public void seekExact(long targetOrd) throws IOException {
int delta = (int) (targetOrd - ordBase - ord);
Expand Down