LUCENE-2569: in Sep codec, make sure reused Docs/AndPositionsEnum can in fact be reused

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@979637 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2010-07-27 10:51:54 +00:00
parent f8fba74632
commit c76e15a33d
1 changed files with 29 additions and 6 deletions

View File

@ -217,24 +217,42 @@ public class SepPostingsReaderImpl extends StandardPostingsReader {
@Override @Override
public DocsEnum docs(FieldInfo fieldInfo, TermState _termState, Bits skipDocs, DocsEnum reuse) throws IOException { public DocsEnum docs(FieldInfo fieldInfo, TermState _termState, Bits skipDocs, DocsEnum reuse) throws IOException {
final SepTermState termState = (SepTermState) _termState; final SepTermState termState = (SepTermState) _termState;
if (reuse == null) { SepDocsEnum docsEnum;
return (new SepDocsEnum()).init(fieldInfo, termState, skipDocs); if (reuse == null || !(reuse instanceof SepDocsEnum)) {
docsEnum = new SepDocsEnum();
} else { } else {
return ((SepDocsEnum) reuse).init(fieldInfo, termState, skipDocs); docsEnum = (SepDocsEnum) reuse;
if (docsEnum.startDocIn != docIn) {
// If you are using ParellelReader, and pass in a
// reused DocsAndPositionsEnum, it could have come
// from another reader also using sep codec
docsEnum = new SepDocsEnum();
} }
} }
return docsEnum.init(fieldInfo, termState, skipDocs);
}
@Override @Override
public DocsAndPositionsEnum docsAndPositions(FieldInfo fieldInfo, TermState _termState, Bits skipDocs, DocsAndPositionsEnum reuse) throws IOException { public DocsAndPositionsEnum docsAndPositions(FieldInfo fieldInfo, TermState _termState, Bits skipDocs, DocsAndPositionsEnum reuse) throws IOException {
assert !fieldInfo.omitTermFreqAndPositions; assert !fieldInfo.omitTermFreqAndPositions;
final SepTermState termState = (SepTermState) _termState; final SepTermState termState = (SepTermState) _termState;
if (reuse == null) { SepDocsAndPositionsEnum postingsEnum;
return (new SepDocsAndPositionsEnum()).init(fieldInfo, termState, skipDocs); if (reuse == null || !(reuse instanceof SepDocsAndPositionsEnum)) {
postingsEnum = new SepDocsAndPositionsEnum();
} else { } else {
return ((SepDocsAndPositionsEnum) reuse).init(fieldInfo, termState, skipDocs); postingsEnum = (SepDocsAndPositionsEnum) reuse;
if (postingsEnum.startDocIn != docIn) {
// If you are using ParellelReader, and pass in a
// reused DocsAndPositionsEnum, it could have come
// from another reader also using sep codec
postingsEnum = new SepDocsAndPositionsEnum();
} }
} }
return postingsEnum.init(fieldInfo, termState, skipDocs);
}
class SepDocsEnum extends DocsEnum { class SepDocsEnum extends DocsEnum {
int docFreq; int docFreq;
int doc; int doc;
@ -253,6 +271,7 @@ public class SepPostingsReaderImpl extends StandardPostingsReader {
private final IntIndexInput.Index docIndex; private final IntIndexInput.Index docIndex;
private final IntIndexInput.Index freqIndex; private final IntIndexInput.Index freqIndex;
private final IntIndexInput.Index posIndex; private final IntIndexInput.Index posIndex;
private final IntIndexInput startDocIn;
// TODO: -- should we do hasProx with 2 different enum classes? // TODO: -- should we do hasProx with 2 different enum classes?
@ -260,6 +279,7 @@ public class SepPostingsReaderImpl extends StandardPostingsReader {
SepSkipListReader skipper; SepSkipListReader skipper;
SepDocsEnum() throws IOException { SepDocsEnum() throws IOException {
startDocIn = docIn;
docReader = docIn.reader(); docReader = docIn.reader();
docIndex = docIn.index(); docIndex = docIn.index();
if (freqIn != null) { if (freqIn != null) {
@ -439,6 +459,8 @@ public class SepPostingsReaderImpl extends StandardPostingsReader {
private final IntIndexInput.Index docIndex; private final IntIndexInput.Index docIndex;
private final IntIndexInput.Index freqIndex; private final IntIndexInput.Index freqIndex;
private final IntIndexInput.Index posIndex; private final IntIndexInput.Index posIndex;
private final IntIndexInput startDocIn;
private long payloadOffset; private long payloadOffset;
private int pendingPosCount; private int pendingPosCount;
@ -452,6 +474,7 @@ public class SepPostingsReaderImpl extends StandardPostingsReader {
private boolean posSeekPending; private boolean posSeekPending;
SepDocsAndPositionsEnum() throws IOException { SepDocsAndPositionsEnum() throws IOException {
startDocIn = docIn;
docReader = docIn.reader(); docReader = docIn.reader();
docIndex = docIn.index(); docIndex = docIn.index();
freqReader = freqIn.reader(); freqReader = freqIn.reader();