001: package org.apache.lucene.index;
002:
003: /**
004: * Licensed to the Apache Software Foundation (ASF) under one or more
005: * contributor license agreements. See the NOTICE file distributed with
006: * this work for additional information regarding copyright ownership.
007: * The ASF licenses this file to You under the Apache License, Version 2.0
008: * (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: */
019:
020: import java.io.IOException;
021: import java.util.Arrays;
022:
023: import org.apache.lucene.store.IndexInput;
024:
025: /**
026: * Implements the skip list reader for the default posting list format
027: * that stores positions and payloads.
028: *
029: */
030: class DefaultSkipListReader extends MultiLevelSkipListReader {
031: private boolean currentFieldStoresPayloads;
032: private long freqPointer[];
033: private long proxPointer[];
034: private int payloadLength[];
035:
036: private long lastFreqPointer;
037: private long lastProxPointer;
038: private int lastPayloadLength;
039:
040: DefaultSkipListReader(IndexInput skipStream, int maxSkipLevels,
041: int skipInterval) {
042: super (skipStream, maxSkipLevels, skipInterval);
043: freqPointer = new long[maxSkipLevels];
044: proxPointer = new long[maxSkipLevels];
045: payloadLength = new int[maxSkipLevels];
046: }
047:
048: void init(long skipPointer, long freqBasePointer,
049: long proxBasePointer, int df, boolean storesPayloads) {
050: super .init(skipPointer, df);
051: this .currentFieldStoresPayloads = storesPayloads;
052: lastFreqPointer = freqBasePointer;
053: lastProxPointer = proxBasePointer;
054:
055: Arrays.fill(freqPointer, freqBasePointer);
056: Arrays.fill(proxPointer, proxBasePointer);
057: Arrays.fill(payloadLength, 0);
058: }
059:
060: /** Returns the freq pointer of the doc to which the last call of
061: * {@link MultiLevelSkipListReader#skipTo(int)} has skipped. */
062: long getFreqPointer() {
063: return lastFreqPointer;
064: }
065:
066: /** Returns the prox pointer of the doc to which the last call of
067: * {@link MultiLevelSkipListReader#skipTo(int)} has skipped. */
068: long getProxPointer() {
069: return lastProxPointer;
070: }
071:
072: /** Returns the payload length of the payload stored just before
073: * the doc to which the last call of {@link MultiLevelSkipListReader#skipTo(int)}
074: * has skipped. */
075: int getPayloadLength() {
076: return lastPayloadLength;
077: }
078:
079: protected void seekChild(int level) throws IOException {
080: super .seekChild(level);
081: freqPointer[level] = lastFreqPointer;
082: proxPointer[level] = lastProxPointer;
083: payloadLength[level] = lastPayloadLength;
084: }
085:
086: protected void setLastSkipData(int level) {
087: super .setLastSkipData(level);
088: lastFreqPointer = freqPointer[level];
089: lastProxPointer = proxPointer[level];
090: lastPayloadLength = payloadLength[level];
091: }
092:
093: protected int readSkipData(int level, IndexInput skipStream)
094: throws IOException {
095: int delta;
096: if (currentFieldStoresPayloads) {
097: // the current field stores payloads.
098: // if the doc delta is odd then we have
099: // to read the current payload length
100: // because it differs from the length of the
101: // previous payload
102: delta = skipStream.readVInt();
103: if ((delta & 1) != 0) {
104: payloadLength[level] = skipStream.readVInt();
105: }
106: delta >>>= 1;
107: } else {
108: delta = skipStream.readVInt();
109: }
110: freqPointer[level] += skipStream.readVInt();
111: proxPointer[level] += skipStream.readVInt();
112:
113: return delta;
114: }
115: }
|