KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lucene > index > SegmentTermPositions


1 package org.apache.lucene.index;
2
3 /**
4  * Copyright 2004 The Apache Software Foundation
5  *
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
9  *
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 JavaDoc;
20
21 import org.apache.lucene.store.IndexInput;
22
23 final class SegmentTermPositions
24 extends SegmentTermDocs implements TermPositions {
25   private IndexInput proxStream;
26   private int proxCount;
27   private int position;
28   
29   SegmentTermPositions(SegmentReader p) {
30     super(p);
31     this.proxStream = (IndexInput)parent.proxStream.clone();
32   }
33
34   final void seek(TermInfo ti) throws IOException JavaDoc {
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 JavaDoc {
42     super.close();
43     proxStream.close();
44   }
45
46   public final int nextPosition() throws IOException JavaDoc {
47     proxCount--;
48     return position += proxStream.readVInt();
49   }
50
51   protected final void skippingDoc() throws IOException JavaDoc {
52     for (int f = freq; f > 0; f--) // skip all positions
53
proxStream.readVInt();
54   }
55
56   public final boolean next() throws IOException JavaDoc {
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     throw new UnsupportedOperationException JavaDoc("TermPositions does not support processing multiple documents in one call. Use TermDocs instead.");
70   }
71
72
73   /** Called by super.skipTo(). */
74   protected void skipProx(long proxPointer) throws IOException JavaDoc {
75     proxStream.seek(proxPointer);
76     proxCount = 0;
77   }
78
79 }
80
Popular Tags