/// <summary> /// Adds a new doc in this term. If this returns null /// then we just skip consuming positions/payloads. /// </summary> public override void StartDoc(int docID, int termDocFreq) { int delta = docID - lastDocID; //System.out.println("SEPW: startDoc: write doc=" + docID + " delta=" + delta + " out.fp=" + docOut); if (docID < 0 || (df > 0 && delta <= 0)) { throw new CorruptIndexException("docs out of order (" + docID + " <= " + lastDocID + " ) (docOut: " + docOut + ")"); } if ((++df % skipInterval) == 0) { // TODO: -- awkward we have to make these two // separate calls to skipper //System.out.println(" buffer skip lastDocID=" + lastDocID); skipListWriter.SetSkipData(lastDocID, storePayloads, lastPayloadLength); skipListWriter.BufferSkip(df); } lastDocID = docID; docOut.Write(delta); if (indexOptions != IndexOptions.DOCS_ONLY) { //System.out.println(" sepw startDoc: write freq=" + termDocFreq); freqOut.Write(termDocFreq); } }
/// <summary> /// Add a new position & payload. </summary> public override void AddPosition(int position, BytesRef payload, int startOffset, int endOffset) { if (Debugging.AssertsEnabled) { Debugging.Assert(indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS); } int delta = position - lastPosition; if (Debugging.AssertsEnabled) { Debugging.Assert(delta >= 0, "position={0} lastPosition={1}", position, lastPosition); // not quite right (if pos=0 is repeated twice we don't catch it) } lastPosition = position; if (storePayloads) { int payloadLength = payload == null ? 0 : payload.Length; if (payloadLength != lastPayloadLength) { lastPayloadLength = payloadLength; // TODO: explore whether we get better compression // by not storing payloadLength into prox stream? posOut.Write((delta << 1) | 1); posOut.Write(payloadLength); } else { posOut.Write(delta << 1); } if (payloadLength > 0) { payloadOut.WriteBytes(payload.Bytes, payload.Offset, payloadLength); } } else { posOut.Write(delta); } lastPosition = position; }