Example #1
0
        /// <summary>
        /// Creates a postings writer with the specified PackedInts overhead ratio </summary>
        // TODO: does this ctor even make sense?
        public Lucene41PostingsWriter(SegmentWriteState state, float acceptableOverheadRatio)
            : base()
        {
            DocOut = state.Directory.CreateOutput(IndexFileNames.SegmentFileName(state.SegmentInfo.Name, state.SegmentSuffix, Lucene41PostingsFormat.DOC_EXTENSION), state.Context);
            IndexOutput posOut  = null;
            IndexOutput payOut  = null;
            bool        success = false;

            try
            {
                CodecUtil.WriteHeader(DocOut, DOC_CODEC, VERSION_CURRENT);
                ForUtil = new ForUtil(acceptableOverheadRatio, DocOut);
                if (state.FieldInfos.HasProx())
                {
                    PosDeltaBuffer = new int[ForUtil.MAX_DATA_SIZE];
                    posOut         = state.Directory.CreateOutput(IndexFileNames.SegmentFileName(state.SegmentInfo.Name, state.SegmentSuffix, Lucene41PostingsFormat.POS_EXTENSION), state.Context);
                    CodecUtil.WriteHeader(posOut, POS_CODEC, VERSION_CURRENT);

                    if (state.FieldInfos.HasPayloads())
                    {
                        PayloadBytes        = new sbyte[128];
                        PayloadLengthBuffer = new int[ForUtil.MAX_DATA_SIZE];
                    }
                    else
                    {
                        PayloadBytes        = null;
                        PayloadLengthBuffer = null;
                    }

                    if (state.FieldInfos.HasOffsets())
                    {
                        OffsetStartDeltaBuffer = new int[ForUtil.MAX_DATA_SIZE];
                        OffsetLengthBuffer     = new int[ForUtil.MAX_DATA_SIZE];
                    }
                    else
                    {
                        OffsetStartDeltaBuffer = null;
                        OffsetLengthBuffer     = null;
                    }

                    if (state.FieldInfos.HasPayloads() || state.FieldInfos.HasOffsets())
                    {
                        payOut = state.Directory.CreateOutput(IndexFileNames.SegmentFileName(state.SegmentInfo.Name, state.SegmentSuffix, Lucene41PostingsFormat.PAY_EXTENSION), state.Context);
                        CodecUtil.WriteHeader(payOut, PAY_CODEC, VERSION_CURRENT);
                    }
                }
                else
                {
                    PosDeltaBuffer         = null;
                    PayloadLengthBuffer    = null;
                    OffsetStartDeltaBuffer = null;
                    OffsetLengthBuffer     = null;
                    PayloadBytes           = null;
                }
                this.PayOut = payOut;
                this.PosOut = posOut;
                success     = true;
            }
            finally
            {
                if (!success)
                {
                    IOUtils.CloseWhileHandlingException(DocOut, posOut, payOut);
                }
            }

            DocDeltaBuffer = new int[ForUtil.MAX_DATA_SIZE];
            FreqBuffer     = new int[ForUtil.MAX_DATA_SIZE];

            // TODO: should we try skipping every 2/4 blocks...?
            SkipWriter = new Lucene41SkipWriter(MaxSkipLevels, Lucene41PostingsFormat.BLOCK_SIZE, state.SegmentInfo.DocCount, DocOut, posOut, payOut);

            Encoded = new sbyte[ForUtil.MAX_ENCODED_SIZE];
        }
        /// <summary>
        /// Creates a postings writer with the specified PackedInts overhead ratio </summary>
        // TODO: does this ctor even make sense?
        public Lucene41PostingsWriter(SegmentWriteState state, float acceptableOverheadRatio)
            : base()
        {
            DocOut = state.Directory.CreateOutput(IndexFileNames.SegmentFileName(state.SegmentInfo.Name, state.SegmentSuffix, Lucene41PostingsFormat.DOC_EXTENSION), state.Context);
            IndexOutput posOut = null;
            IndexOutput payOut = null;
            bool success = false;
            try
            {
                CodecUtil.WriteHeader(DocOut, DOC_CODEC, VERSION_CURRENT);
                ForUtil = new ForUtil(acceptableOverheadRatio, DocOut);
                if (state.FieldInfos.HasProx())
                {
                    PosDeltaBuffer = new int[ForUtil.MAX_DATA_SIZE];
                    posOut = state.Directory.CreateOutput(IndexFileNames.SegmentFileName(state.SegmentInfo.Name, state.SegmentSuffix, Lucene41PostingsFormat.POS_EXTENSION), state.Context);
                    CodecUtil.WriteHeader(posOut, POS_CODEC, VERSION_CURRENT);

                    if (state.FieldInfos.HasPayloads())
                    {
                        PayloadBytes = new sbyte[128];
                        PayloadLengthBuffer = new int[ForUtil.MAX_DATA_SIZE];
                    }
                    else
                    {
                        PayloadBytes = null;
                        PayloadLengthBuffer = null;
                    }

                    if (state.FieldInfos.HasOffsets())
                    {
                        OffsetStartDeltaBuffer = new int[ForUtil.MAX_DATA_SIZE];
                        OffsetLengthBuffer = new int[ForUtil.MAX_DATA_SIZE];
                    }
                    else
                    {
                        OffsetStartDeltaBuffer = null;
                        OffsetLengthBuffer = null;
                    }

                    if (state.FieldInfos.HasPayloads() || state.FieldInfos.HasOffsets())
                    {
                        payOut = state.Directory.CreateOutput(IndexFileNames.SegmentFileName(state.SegmentInfo.Name, state.SegmentSuffix, Lucene41PostingsFormat.PAY_EXTENSION), state.Context);
                        CodecUtil.WriteHeader(payOut, PAY_CODEC, VERSION_CURRENT);
                    }
                }
                else
                {
                    PosDeltaBuffer = null;
                    PayloadLengthBuffer = null;
                    OffsetStartDeltaBuffer = null;
                    OffsetLengthBuffer = null;
                    PayloadBytes = null;
                }
                this.PayOut = payOut;
                this.PosOut = posOut;
                success = true;
            }
            finally
            {
                if (!success)
                {
                    IOUtils.CloseWhileHandlingException(DocOut, posOut, payOut);
                }
            }

            DocDeltaBuffer = new int[ForUtil.MAX_DATA_SIZE];
            FreqBuffer = new int[ForUtil.MAX_DATA_SIZE];

            // TODO: should we try skipping every 2/4 blocks...?
            SkipWriter = new Lucene41SkipWriter(MaxSkipLevels, Lucene41PostingsFormat.BLOCK_SIZE, state.SegmentInfo.DocCount, DocOut, posOut, payOut);

            Encoded = new sbyte[ForUtil.MAX_ENCODED_SIZE];
        }