KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lucene > search > PhrasePositions


1 package org.apache.lucene.search;
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 import org.apache.lucene.index.*;
21
22 final class PhrasePositions {
23   int doc; // current doc
24
int position; // position in doc
25
int count; // remaining pos in this doc
26
int offset; // position in phrase
27
TermPositions tp; // stream of positions
28
PhrasePositions next; // used to make lists
29

30   PhrasePositions(TermPositions t, int o) {
31     tp = t;
32     offset = o;
33   }
34
35   final boolean next() throws IOException JavaDoc { // increments to next doc
36
if (!tp.next()) {
37       tp.close(); // close stream
38
doc = Integer.MAX_VALUE; // sentinel value
39
return false;
40     }
41     doc = tp.doc();
42     position = 0;
43     return true;
44   }
45
46   final boolean skipTo(int target) throws IOException JavaDoc {
47     if (!tp.skipTo(target)) {
48       tp.close(); // close stream
49
doc = Integer.MAX_VALUE; // sentinel value
50
return false;
51     }
52     doc = tp.doc();
53     position = 0;
54     return true;
55   }
56
57
58   final void firstPosition() throws IOException JavaDoc {
59     count = tp.freq(); // read first pos
60
nextPosition();
61   }
62
63   final boolean nextPosition() throws IOException JavaDoc {
64     if (count-- > 0) { // read subsequent pos's
65
position = tp.nextPosition() - offset;
66       return true;
67     } else
68       return false;
69   }
70 }
71
Popular Tags