01 package gate.creole.annic.apache.lucene.index;
02
03 /**
04 * Copyright 2004 The Apache Software Foundation
05 *
06 * Licensed under the Apache License, Version 2.0 (the "License");
07 * you may not use this file except in compliance with the License.
08 * You may obtain a copy of the License at
09 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
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.
17 */
18
19 import java.io.IOException;
20
21 import gate.creole.annic.apache.lucene.store.InputStream;
22
23 final class SegmentTermPositions
24 extends SegmentTermDocs implements TermPositions {
25 private InputStream proxStream;
26 private int proxCount;
27 private int position;
28
29 SegmentTermPositions(SegmentReader p) throws IOException {
30 super(p);
31 this.proxStream = (InputStream)parent.proxStream.clone();
32 }
33
34 final void seek(TermInfo ti) throws IOException {
35 super.seek(ti);
36 if (ti != null)
37 proxStream.seek(ti.proxPointer);
38 proxCount = 0;
39 }
40
41 public final void close() throws IOException {
42 super.close();
43 proxStream.close();
44 }
45
46 public final int nextPosition() throws IOException {
47 proxCount--;
48 return position += proxStream.readVInt();
49 }
50
51 protected final void skippingDoc() throws IOException {
52 for (int f = freq; f > 0; f--) // skip all positions
53 proxStream.readVInt();
54 }
55
56 public final boolean next() throws IOException {
57 for (int f = proxCount; f > 0; f--) // skip unread positions
58 proxStream.readVInt();
59
60 if (super.next()) { // run super
61 proxCount = freq; // note frequency
62 position = 0; // reset position
63 return true;
64 }
65 return false;
66 }
67
68 public final int read(final int[] docs, final int[] freqs)
69 throws IOException {
70 throw new UnsupportedOperationException("TermPositions does not support processing multiple documents in one call. Use TermDocs instead.");
71 }
72
73
74 /** Called by super.skipTo(). */
75 protected void skipProx(long proxPointer) throws IOException {
76 proxStream.seek(proxPointer);
77 proxCount = 0;
78 }
79
80 }
|