1 package org.apache.lucene.store.instantiated;
4 * Copyright 2006 The Apache Software Foundation
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import org.apache.lucene.index.TermPositions;
21 import java.io.IOException;
24 * A {@link org.apache.lucene.index.TermPositions} navigating an {@link InstantiatedIndexReader}.
26 public class InstantiatedTermPositions
27 extends InstantiatedTermDocs
28 implements TermPositions {
30 public int getPayloadLength() {
31 return currentDocumentInformation.getPayloads()[currentTermPositionIndex].length;
34 public byte[] getPayload(byte[] data, int offset) throws IOException {
35 byte[] payloads = currentDocumentInformation.getPayloads()[currentTermPositionIndex];
37 // read payloads lazily
38 if (data == null || data.length - offset < getPayloadLength()) {
39 // the array is too small to store the payload data,
42 System.arraycopy(payloads, 0, data, offset, payloads.length);
47 public boolean isPayloadAvailable() {
48 return currentDocumentInformation.getPayloads()[currentTermPositionIndex] != null;
51 public InstantiatedTermPositions(InstantiatedIndexReader reader) {
56 * Returns next position in the current document. It is an error to call
57 * this more than {@link #freq()} times
58 * without calling {@link #next()}<p> This is
59 * invalid until {@link #next()} is called for
62 public int nextPosition() {
63 currentTermPositionIndex++;
64 // if you get an array out of index exception here,
65 // it might be due to currentDocumentInformation.getIndexFromTerm not being set!!
66 return currentDocumentInformation.getTermPositions()[currentTermPositionIndex];
69 private int currentTermPositionIndex;
72 * Moves to the next pair in the enumeration.
73 * <p> Returns true if there is such a next pair in the enumeration.
76 public boolean next() {
77 currentTermPositionIndex = -1;
82 * Skips entries to the first beyond the current whose document number is
83 * greater than or equal to <currentTermPositionIndex>target</currentTermPositionIndex>. <p>Returns true iff there is such
84 * an entry. <p>Behaves as if written: <pre>
85 * boolean skipTo(int target) {
89 * } while (target > doc());
93 * Some implementations are considerably more efficient than that.
96 public boolean skipTo(int target) {
97 currentTermPositionIndex = -1;
98 return super.skipTo(target);