mirror of https://github.com/apache/lucene.git
LUCENE-2462: remove DocsAndPositionsEnum.getPayloadLength
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@944320 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
cb13ac0de9
commit
4e93b11311
|
@ -685,7 +685,7 @@ public class CheckIndex {
|
|||
throw new RuntimeException("term " + term + ": doc " + doc + ": pos " + pos + " < lastPos " + lastPos);
|
||||
}
|
||||
lastPos = pos;
|
||||
if (postings.getPayloadLength() != 0) {
|
||||
if (postings.hasPayload()) {
|
||||
postings.getPayload();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1393,7 +1393,7 @@ class DirectoryReader extends IndexReader implements Cloneable {
|
|||
return ((TermPositions)current).nextPosition();
|
||||
}
|
||||
|
||||
public int getPayloadLength() {
|
||||
public int getPayloadLength() throws IOException {
|
||||
return ((TermPositions)current).getPayloadLength();
|
||||
}
|
||||
|
||||
|
|
|
@ -29,9 +29,6 @@ public abstract class DocsAndPositionsEnum extends DocsEnum {
|
|||
* the behavior is not defined. */
|
||||
public abstract int nextPosition() throws IOException;
|
||||
|
||||
/** Returns length of payload at current position */
|
||||
public abstract int getPayloadLength();
|
||||
|
||||
/** Returns the payload at this position, or null if no
|
||||
* payload was indexed. */
|
||||
public abstract BytesRef getPayload() throws IOException;
|
||||
|
|
|
@ -67,7 +67,7 @@ public class FilterIndexReader extends IndexReader {
|
|||
return ((TermPositions) this.in).nextPosition();
|
||||
}
|
||||
|
||||
public int getPayloadLength() {
|
||||
public int getPayloadLength() throws IOException {
|
||||
return ((TermPositions) this.in).getPayloadLength();
|
||||
}
|
||||
|
||||
|
|
|
@ -305,11 +305,6 @@ class LegacyFieldsEnum extends FieldsEnum {
|
|||
return tp.nextPosition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPayloadLength() {
|
||||
return tp.getPayloadLength();
|
||||
}
|
||||
|
||||
private BytesRef payload;
|
||||
|
||||
@Override
|
||||
|
|
|
@ -111,11 +111,6 @@ public final class MultiDocsAndPositionsEnum extends DocsAndPositionsEnum {
|
|||
return current.nextPosition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPayloadLength() {
|
||||
return current.getPayloadLength();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPayload() {
|
||||
return current.hasPayload();
|
||||
|
|
|
@ -721,7 +721,7 @@ public class ParallelReader extends IndexReader {
|
|||
return ((TermPositions)termDocs).nextPosition();
|
||||
}
|
||||
|
||||
public int getPayloadLength() {
|
||||
public int getPayloadLength() throws IOException {
|
||||
return ((TermPositions)termDocs).getPayloadLength();
|
||||
}
|
||||
|
||||
|
|
|
@ -1653,19 +1653,31 @@ public class SegmentReader extends IndexReader implements Cloneable {
|
|||
throw new UnsupportedOperationException("TermPositions does not support processing multiple documents in one call. Use TermDocs instead.");
|
||||
}
|
||||
|
||||
public int nextPosition() throws IOException {
|
||||
public int nextPosition() throws IOException {
|
||||
pendingPayload = null;
|
||||
if (!any || postingsEnum == null) {
|
||||
return 0;
|
||||
} else {
|
||||
return postingsEnum.nextPosition();
|
||||
}
|
||||
}
|
||||
|
||||
private BytesRef pendingPayload;
|
||||
|
||||
public int getPayloadLength() {
|
||||
public int getPayloadLength() throws IOException {
|
||||
if (!any || postingsEnum == null) {
|
||||
return 0;
|
||||
} else {
|
||||
return postingsEnum.getPayloadLength();
|
||||
if (pendingPayload == null) {
|
||||
if (!postingsEnum.hasPayload()) {
|
||||
return 0;
|
||||
}
|
||||
pendingPayload = postingsEnum.getPayload();
|
||||
}
|
||||
if (pendingPayload == null) {
|
||||
return 0;
|
||||
}
|
||||
return pendingPayload.length;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1673,17 +1685,26 @@ public class SegmentReader extends IndexReader implements Cloneable {
|
|||
if (!any || postingsEnum == null) {
|
||||
return null;
|
||||
}
|
||||
final BytesRef payload = postingsEnum.getPayload();
|
||||
if (pendingPayload == null) {
|
||||
if (!postingsEnum.hasPayload()) {
|
||||
return null;
|
||||
}
|
||||
pendingPayload = postingsEnum.getPayload();
|
||||
}
|
||||
if (pendingPayload == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// old API would always used passed in bytes if it
|
||||
// "fits", else allocate new:
|
||||
if (bytes != null && payload.length <= bytes.length - offset) {
|
||||
System.arraycopy(payload.bytes, payload.offset, bytes, offset, payload.length);
|
||||
if (bytes != null && pendingPayload.length <= bytes.length - offset) {
|
||||
System.arraycopy(pendingPayload.bytes, pendingPayload.offset, bytes, offset, pendingPayload.length);
|
||||
return bytes;
|
||||
} else if (payload.offset == 0 && payload.length == payload.bytes.length) {
|
||||
return payload.bytes;
|
||||
} else if (pendingPayload.offset == 0 && pendingPayload.length == pendingPayload.bytes.length) {
|
||||
return pendingPayload.bytes;
|
||||
} else {
|
||||
final byte[] retBytes = new byte[payload.length];
|
||||
System.arraycopy(payload.bytes, payload.offset, retBytes, 0, payload.length);
|
||||
final byte[] retBytes = new byte[pendingPayload.length];
|
||||
System.arraycopy(pendingPayload.bytes, pendingPayload.offset, retBytes, 0, pendingPayload.length);
|
||||
return retBytes;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ public interface TermPositions
|
|||
* the first time.<br>
|
||||
* @return length of the current payload in number of bytes
|
||||
*/
|
||||
int getPayloadLength();
|
||||
int getPayloadLength() throws IOException;
|
||||
|
||||
/**
|
||||
* Returns the payload data at the current term position.
|
||||
|
|
|
@ -102,12 +102,6 @@ public final class MappingMultiDocsAndPositionsEnum extends DocsAndPositionsEnum
|
|||
return current.nextPosition();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getPayloadLength() {
|
||||
return current.getPayloadLength();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BytesRef getPayload() throws IOException {
|
||||
BytesRef payload = current.getPayload();
|
||||
|
|
|
@ -79,9 +79,8 @@ public abstract class PostingsConsumer {
|
|||
this.startDoc(doc, freq);
|
||||
for(int i=0;i<freq;i++) {
|
||||
final int position = postingsEnum.nextPosition();
|
||||
final int payloadLength = postingsEnum.getPayloadLength();
|
||||
final BytesRef payload;
|
||||
if (payloadLength > 0) {
|
||||
if (postingsEnum.hasPayload()) {
|
||||
payload = postingsEnum.getPayload();
|
||||
} else {
|
||||
payload = null;
|
||||
|
|
|
@ -456,11 +456,6 @@ public class PreFlexFields extends FieldsProducer {
|
|||
return pos.nextPosition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPayloadLength() {
|
||||
return pos.getPayloadLength();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPayload() {
|
||||
return pos.isPayloadAvailable();
|
||||
|
|
|
@ -357,11 +357,6 @@ public class PulsingPostingsReaderImpl extends StandardPostingsReader {
|
|||
return pos.pos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPayloadLength() {
|
||||
return payloadRetrieved || pos.payload == null ? 0 : pos.payload.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPayload() {
|
||||
return !payloadRetrieved && pos.payload != null && pos.payload.length > 0;
|
||||
|
|
|
@ -638,11 +638,6 @@ public class SepPostingsReaderImpl extends StandardPostingsReader {
|
|||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPayloadLength() {
|
||||
return payloadLength;
|
||||
}
|
||||
|
||||
private BytesRef payload;
|
||||
|
||||
@Override
|
||||
|
|
|
@ -508,11 +508,6 @@ class UnionDocsAndPositionsEnum extends DocsAndPositionsEnum {
|
|||
return _posList.next();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPayloadLength() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BytesRef getPayload() {
|
||||
throw new UnsupportedOperationException();
|
||||
|
|
|
@ -435,11 +435,6 @@ public class TestExternalCodecs extends LuceneTestCase {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPayloadLength() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BytesRef getPayload() {
|
||||
return null;
|
||||
|
|
|
@ -190,8 +190,8 @@ public class FlexTestUtil {
|
|||
assertEquals(position, termPos.nextPosition());
|
||||
assertEquals(postings.hasPayload(), termPos.isPayloadAvailable());
|
||||
if (postings.hasPayload()) {
|
||||
assertEquals(postings.getPayloadLength(), termPos.getPayloadLength());
|
||||
BytesRef payload = postings.getPayload();
|
||||
assertEquals(payload.length, termPos.getPayloadLength());
|
||||
byte[] b2 = termPos.getPayload(null, 0);
|
||||
assertNotNull(payload);
|
||||
assertNotNull(b2);
|
||||
|
@ -337,9 +337,9 @@ public class FlexTestUtil {
|
|||
assertEquals(position, termPos.nextPosition());
|
||||
assertEquals(postings.hasPayload(), termPos.isPayloadAvailable());
|
||||
if (postings.hasPayload()) {
|
||||
assertEquals(postings.getPayloadLength(), termPos.getPayloadLength());
|
||||
if (rand.nextInt(3) <= 1) {
|
||||
BytesRef payload = postings.getPayload();
|
||||
assertEquals(payload.length, termPos.getPayloadLength());
|
||||
byte[] b2 = termPos.getPayload(null, 0);
|
||||
assertNotNull(payload);
|
||||
assertNotNull(b2);
|
||||
|
@ -525,8 +525,8 @@ public class FlexTestUtil {
|
|||
assertEquals(pos1, pos2);
|
||||
assertEquals(postings.hasPayload(), termPositions.isPayloadAvailable());
|
||||
if (postings.hasPayload()) {
|
||||
assertEquals(postings.getPayloadLength(), termPositions.getPayloadLength());
|
||||
BytesRef b1 = postings.getPayload();
|
||||
assertEquals(b1.length, termPositions.getPayloadLength());
|
||||
byte[] b2 = termPositions.getPayload(null, 0);
|
||||
assertNotNull(b1);
|
||||
assertNotNull(b2);
|
||||
|
|
|
@ -309,14 +309,6 @@ public class TestPayloads extends LuceneTestCase {
|
|||
* Test multiple call of getPayload()
|
||||
*/
|
||||
tp.getPayload(null, 0);
|
||||
try {
|
||||
// it is forbidden to call getPayload() more than once
|
||||
// without calling nextPosition()
|
||||
tp.getPayload(null, 0);
|
||||
fail("Expected exception not thrown");
|
||||
} catch (Exception expected) {
|
||||
// expected exception
|
||||
}
|
||||
|
||||
reader.close();
|
||||
|
||||
|
|
Loading…
Reference in New Issue