/// <summary>
        /// Add a new position & payload </summary>
        public override void AddPosition(int position, BytesRef payload, int startOffset, int endOffset)
        {
            // if (DEBUG) {
            //   System.out.println("FPW.addPosition pos=" + position + " posBufferUpto=" + posBufferUpto + (fieldHasPayloads ? " payloadByteUpto=" + payloadByteUpto: ""));
            // }
            PosDeltaBuffer[PosBufferUpto] = position - LastPosition;
            if (FieldHasPayloads)
            {
                if (payload == null || payload.Length == 0)
                {
                    // no payload
                    PayloadLengthBuffer[PosBufferUpto] = 0;
                }
                else
                {
                    PayloadLengthBuffer[PosBufferUpto] = payload.Length;
                    if (PayloadByteUpto + payload.Length > PayloadBytes.Length)
                    {
                        PayloadBytes = ArrayUtil.Grow(PayloadBytes, PayloadByteUpto + payload.Length);
                    }
                    Array.Copy(payload.Bytes, payload.Offset, PayloadBytes, PayloadByteUpto, payload.Length);
                    PayloadByteUpto += payload.Length;
                }
            }

            if (FieldHasOffsets)
            {
                Debug.Assert(startOffset >= LastStartOffset);
                Debug.Assert(endOffset >= startOffset);
                OffsetStartDeltaBuffer[PosBufferUpto] = startOffset - LastStartOffset;
                OffsetLengthBuffer[PosBufferUpto]     = endOffset - startOffset;
                LastStartOffset = startOffset;
            }

            PosBufferUpto++;
            LastPosition = position;
            if (PosBufferUpto == Lucene41PostingsFormat.BLOCK_SIZE)
            {
                // if (DEBUG) {
                //   System.out.println("  write pos bulk block @ fp=" + posOut.getFilePointer());
                // }
                ForUtil.WriteBlock(PosDeltaBuffer, Encoded, PosOut);

                if (FieldHasPayloads)
                {
                    ForUtil.WriteBlock(PayloadLengthBuffer, Encoded, PayOut);
                    PayOut.WriteVInt(PayloadByteUpto);
                    PayOut.WriteBytes(PayloadBytes, 0, PayloadByteUpto);
                    PayloadByteUpto = 0;
                }
                if (FieldHasOffsets)
                {
                    ForUtil.WriteBlock(OffsetStartDeltaBuffer, Encoded, PayOut);
                    ForUtil.WriteBlock(OffsetLengthBuffer, Encoded, PayOut);
                }
                PosBufferUpto = 0;
            }
        }
Exemplo n.º 2
0
            public bool MoveNext()
            {
                if (!counts.MoveNext())
                {
                    return(false);
                }

                int count   = (int)counts.Current;
                int maxSize = count * 9; // worst case

                if (maxSize > buffer.Length)
                {
                    buffer = ArrayUtil.Grow(buffer, maxSize);
                }

                EncodeValues(count);


                _current.Bytes  = buffer;
                _current.Offset = 0;
                _current.Length = @out.Position;

                return(true);
            }