mirror of https://github.com/apache/lucene.git
fix bug on TempNestedPF
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3069@1515695 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
980ea4db59
commit
9b18f12d6e
|
@ -0,0 +1,90 @@
|
|||
package org.apache.lucene.codecs.temp;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.lucene.codecs.FieldsConsumer;
|
||||
import org.apache.lucene.codecs.FieldsProducer;
|
||||
import org.apache.lucene.codecs.PostingsFormat;
|
||||
import org.apache.lucene.codecs.TempPostingsReaderBase;
|
||||
import org.apache.lucene.codecs.TempPostingsWriterBase;
|
||||
import org.apache.lucene.index.SegmentReadState;
|
||||
import org.apache.lucene.index.SegmentWriteState;
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
|
||||
/**
|
||||
* Pulsing(1, Pulsing(2, Lucene41))
|
||||
* @lucene.experimental
|
||||
*/
|
||||
// TODO: if we create PulsingPostingsBaseFormat then we
|
||||
// can simplify this? note: I don't like the *BaseFormat
|
||||
// hierarchy, maybe we can clean that up...
|
||||
public final class TempNestedPulsingPostingsFormat extends PostingsFormat {
|
||||
public TempNestedPulsingPostingsFormat() {
|
||||
super("TempNestedPulsing");
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldsConsumer fieldsConsumer(SegmentWriteState state) throws IOException {
|
||||
TempPostingsWriterBase docsWriter = null;
|
||||
TempPostingsWriterBase pulsingWriterInner = null;
|
||||
TempPostingsWriterBase pulsingWriter = null;
|
||||
|
||||
// Terms dict
|
||||
boolean success = false;
|
||||
try {
|
||||
docsWriter = new TempPostingsWriter(state);
|
||||
|
||||
pulsingWriterInner = new TempPulsingPostingsWriter(state, 2, docsWriter);
|
||||
pulsingWriter = new TempPulsingPostingsWriter(state, 1, pulsingWriterInner);
|
||||
FieldsConsumer ret = new TempBlockTreeTermsWriter(state, pulsingWriter,
|
||||
TempBlockTreeTermsWriter.DEFAULT_MIN_BLOCK_SIZE, TempBlockTreeTermsWriter.DEFAULT_MAX_BLOCK_SIZE);
|
||||
success = true;
|
||||
return ret;
|
||||
} finally {
|
||||
if (!success) {
|
||||
IOUtils.closeWhileHandlingException(docsWriter, pulsingWriterInner, pulsingWriter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldsProducer fieldsProducer(SegmentReadState state) throws IOException {
|
||||
TempPostingsReaderBase docsReader = null;
|
||||
TempPostingsReaderBase pulsingReaderInner = null;
|
||||
TempPostingsReaderBase pulsingReader = null;
|
||||
boolean success = false;
|
||||
try {
|
||||
docsReader = new TempPostingsReader(state.directory, state.fieldInfos, state.segmentInfo, state.context, state.segmentSuffix);
|
||||
pulsingReaderInner = new TempPulsingPostingsReader(state, docsReader);
|
||||
pulsingReader = new TempPulsingPostingsReader(state, pulsingReaderInner);
|
||||
FieldsProducer ret = new TempBlockTreeTermsReader(
|
||||
state.directory, state.fieldInfos, state.segmentInfo,
|
||||
pulsingReader,
|
||||
state.context,
|
||||
state.segmentSuffix);
|
||||
success = true;
|
||||
return ret;
|
||||
} finally {
|
||||
if (!success) {
|
||||
IOUtils.closeWhileHandlingException(docsReader, pulsingReaderInner, pulsingReader);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -70,10 +70,12 @@ public class TempPulsingPostingsReader extends TempPostingsReaderBase {
|
|||
version = CodecUtil.checkHeader(termsIn, TempPulsingPostingsWriter.CODEC,
|
||||
TempPulsingPostingsWriter.VERSION_START,
|
||||
TempPulsingPostingsWriter.VERSION_CURRENT);
|
||||
// nocommit: here open file to load field summary
|
||||
maxPositions = termsIn.readVInt();
|
||||
wrappedPostingsReader.init(termsIn);
|
||||
if (version >= TempPulsingPostingsWriter.VERSION_META_ARRAY) {
|
||||
if (wrappedPostingsReader instanceof TempPulsingPostingsReader ||
|
||||
version < TempPulsingPostingsWriter.VERSION_META_ARRAY) {
|
||||
fields = null;
|
||||
} else {
|
||||
fields = new TreeMap<Integer, Integer>();
|
||||
String summaryFileName = IndexFileNames.segmentFileName(segmentState.segmentInfo.name, segmentState.segmentSuffix, TempPulsingPostingsWriter.SUMMARY_EXTENSION);
|
||||
IndexInput in = null;
|
||||
|
@ -90,9 +92,6 @@ public class TempPulsingPostingsReader extends TempPostingsReaderBase {
|
|||
} finally {
|
||||
IOUtils.closeWhileHandlingException(in);
|
||||
}
|
||||
} else {
|
||||
assert false;
|
||||
fields = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -164,11 +163,6 @@ public class TempPulsingPostingsReader extends TempPostingsReaderBase {
|
|||
long count = fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 ? termState.totalTermFreq : termState.docFreq;
|
||||
//System.out.println(" count=" + count + " threshold=" + maxPositions);
|
||||
|
||||
// term dict have no chance to init this
|
||||
// nocommit: nuke this?
|
||||
if (termState.termBlockOrd == 0) {
|
||||
termState.wrappedTermState.termBlockOrd = 0;
|
||||
}
|
||||
if (count <= maxPositions) {
|
||||
// Inlined into terms dict -- just read the byte[] blob in,
|
||||
// but don't decode it now (we only decode when a DocsEnum
|
||||
|
@ -183,14 +177,12 @@ public class TempPulsingPostingsReader extends TempPostingsReaderBase {
|
|||
// blob for this term)...
|
||||
in.readBytes(termState.postings, 0, termState.postingsSize);
|
||||
//System.out.println(" inlined bytes=" + termState.postingsSize);
|
||||
termState.absolute = absolute ? true : termState.absolute;
|
||||
termState.absolute = termState.absolute || absolute;
|
||||
} else {
|
||||
//System.out.println(" not inlined");
|
||||
final int longsSize = fields.get(fieldInfo.number);
|
||||
final int longsSize = fields == null ? 0 : fields.get(fieldInfo.number);
|
||||
if (termState.longs == null) {
|
||||
termState.longs = new long[longsSize];
|
||||
} else {
|
||||
assert termState.longs.length == longsSize;
|
||||
}
|
||||
for (int i = 0; i < longsSize; i++) {
|
||||
termState.longs[i] = in.readVLong();
|
||||
|
@ -199,7 +191,6 @@ public class TempPulsingPostingsReader extends TempPostingsReaderBase {
|
|||
termState.wrappedTermState.docFreq = termState.docFreq;
|
||||
termState.wrappedTermState.totalTermFreq = termState.totalTermFreq;
|
||||
wrappedPostingsReader.decodeTerm(termState.longs, in, fieldInfo, termState.wrappedTermState, termState.absolute);
|
||||
termState.wrappedTermState.termBlockOrd++;
|
||||
termState.absolute = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -384,7 +384,6 @@ public final class TempPulsingPostingsWriter extends TempPostingsWriterBase {
|
|||
assert empty.length == 0;
|
||||
this.absolute = this.absolute || absolute;
|
||||
if (state.bytes == null) {
|
||||
assert longsSize > 0;
|
||||
wrappedPostingsWriter.encodeTerm(longs, buffer, fieldInfo, state.wrappedState, this.absolute);
|
||||
for (int i = 0; i < longsSize; i++) {
|
||||
out.writeVLong(longs[i]);
|
||||
|
@ -395,14 +394,17 @@ public final class TempPulsingPostingsWriter extends TempPostingsWriterBase {
|
|||
} else {
|
||||
out.writeVInt(state.bytes.length);
|
||||
out.writeBytes(state.bytes, 0, state.bytes.length);
|
||||
this.absolute = absolute ? true : this.absolute;
|
||||
this.absolute = this.absolute || absolute;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
wrappedPostingsWriter.close();
|
||||
assert (VERSION_CURRENT >= VERSION_META_ARRAY);
|
||||
if (wrappedPostingsWriter instanceof TempPulsingPostingsWriter ||
|
||||
VERSION_CURRENT < VERSION_META_ARRAY) {
|
||||
return;
|
||||
}
|
||||
String summaryFileName = IndexFileNames.segmentFileName(segmentState.segmentInfo.name, segmentState.segmentSuffix, SUMMARY_EXTENSION);
|
||||
IndexOutput out = null;
|
||||
try {
|
||||
|
|
|
@ -22,3 +22,4 @@ org.apache.lucene.codecs.temp.TempBlockPostingsFormat
|
|||
org.apache.lucene.codecs.temp.TempPulsing41PostingsFormat
|
||||
org.apache.lucene.codecs.temp.TempFSTPulsing41PostingsFormat
|
||||
org.apache.lucene.codecs.temp.TempFSTOrdPulsing41PostingsFormat
|
||||
org.apache.lucene.codecs.temp.TempNestedPulsingPostingsFormat
|
||||
|
|
Loading…
Reference in New Issue