public BlockTermsReader(TermsIndexReaderBase indexReader, Directory dir, FieldInfos fieldInfos, SegmentInfo info,
PostingsReaderBase postingsReader, IOContext context,
String segmentSuffix)
{
_postingsReader = postingsReader;
_input =
dir.OpenInput(
IndexFileNames.SegmentFileName(info.Name, segmentSuffix, BlockTermsWriter.TERMS_EXTENSION),
context);
var success = false;
try
{
_version = ReadHeader(_input);
// Have PostingsReader init itself
postingsReader.Init(_input);
// Read per-field details
SeekDir(_input, _dirOffset);
int numFields = _input.ReadVInt();
if (numFields < 0)
{
throw new CorruptIndexException(String.Format("Invalid number of fields: {0}, Resource: {1}",
numFields, _input));
}
for (var i = 0; i < numFields; i++)
{
var field = _input.ReadVInt();
var numTerms = _input.ReadVLong();
Debug.Assert(numTerms >= 0);
var termsStartPointer = _input.ReadVLong();
var fieldInfo = fieldInfos.FieldInfo(field);
var sumTotalTermFreq = fieldInfo.FieldIndexOptions == FieldInfo.IndexOptions.DOCS_ONLY
? -1
: _input.ReadVLong();
var sumDocFreq = _input.ReadVLong();
var docCount = _input.ReadVInt();
var longsSize = _version >= BlockTermsWriter.VERSION_META_ARRAY ? _input.ReadVInt() : 0;
if (docCount < 0 || docCount > info.DocCount)
{
// #docs with field must be <= #docs
throw new CorruptIndexException(
String.Format("Invalid DocCount: {0}, MaxDoc: {1}, Resource: {2}", docCount, info.DocCount,
_input));
}
if (sumDocFreq < docCount)
{
// #postings must be >= #docs with field
throw new CorruptIndexException(
String.Format("Invalid sumDocFreq: {0}, DocCount: {1}, Resource: {2}", sumDocFreq, docCount,
_input));
}
if (sumTotalTermFreq != -1 && sumTotalTermFreq < sumDocFreq)
{
// #positions must be >= #postings
throw new CorruptIndexException(
String.Format("Invalid sumTotalTermFreq: {0}, sumDocFreq: {1}, Resource: {2}",
sumTotalTermFreq, sumDocFreq, _input));
}
try
{
_fields.Add(fieldInfo.Name,
new FieldReader(fieldInfo, this, numTerms, termsStartPointer, sumTotalTermFreq, sumDocFreq,
docCount,
longsSize));
}
catch (ArgumentException)
{
throw new CorruptIndexException(String.Format("Duplicate fields: {0}, Resource: {1}",
fieldInfo.Name, _input));
}
}
success = true;
}
finally
{
if (!success)
{
_input.Dispose();
}
}
_indexReader = indexReader;
}