1 package org.apache.lucene.index;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 import java.io.IOException;
21 import java.util.Arrays;
23 import org.apache.lucene.store.IndexInput;
26 * Implements the skip list reader for the default posting list format
27 * that stores positions and payloads.
30 class DefaultSkipListReader extends MultiLevelSkipListReader {
31 private boolean currentFieldStoresPayloads;
32 private long freqPointer[];
33 private long proxPointer[];
34 private int payloadLength[];
36 private long lastFreqPointer;
37 private long lastProxPointer;
38 private int lastPayloadLength;
41 DefaultSkipListReader(IndexInput skipStream, int maxSkipLevels, int skipInterval) {
42 super(skipStream, maxSkipLevels, skipInterval);
43 freqPointer = new long[maxSkipLevels];
44 proxPointer = new long[maxSkipLevels];
45 payloadLength = new int[maxSkipLevels];
48 void init(long skipPointer, long freqBasePointer, long proxBasePointer, int df, boolean storesPayloads) {
49 super.init(skipPointer, df);
50 this.currentFieldStoresPayloads = storesPayloads;
51 lastFreqPointer = freqBasePointer;
52 lastProxPointer = proxBasePointer;
54 Arrays.fill(freqPointer, freqBasePointer);
55 Arrays.fill(proxPointer, proxBasePointer);
56 Arrays.fill(payloadLength, 0);
59 /** Returns the freq pointer of the doc to which the last call of
60 * {@link MultiLevelSkipListReader#skipTo(int)} has skipped. */
61 long getFreqPointer() {
62 return lastFreqPointer;
65 /** Returns the prox pointer of the doc to which the last call of
66 * {@link MultiLevelSkipListReader#skipTo(int)} has skipped. */
67 long getProxPointer() {
68 return lastProxPointer;
71 /** Returns the payload length of the payload stored just before
72 * the doc to which the last call of {@link MultiLevelSkipListReader#skipTo(int)}
74 int getPayloadLength() {
75 return lastPayloadLength;
79 protected void seekChild(int level) throws IOException {
80 super.seekChild(level);
81 freqPointer[level] = lastFreqPointer;
82 proxPointer[level] = lastProxPointer;
83 payloadLength[level] = lastPayloadLength;
87 protected void setLastSkipData(int level) {
88 super.setLastSkipData(level);
89 lastFreqPointer = freqPointer[level];
90 lastProxPointer = proxPointer[level];
91 lastPayloadLength = payloadLength[level];
96 protected int readSkipData(int level, IndexInput skipStream) throws IOException {
98 if (currentFieldStoresPayloads) {
99 // the current field stores payloads.
100 // if the doc delta is odd then we have
101 // to read the current payload length
102 // because it differs from the length of the
104 delta = skipStream.readVInt();
105 if ((delta & 1) != 0) {
106 payloadLength[level] = skipStream.readVInt();
110 delta = skipStream.readVInt();
112 freqPointer[level] += skipStream.readVInt();
113 proxPointer[level] += skipStream.readVInt();