01 package gate.creole.annic.apache.lucene.search;
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 import gate.creole.annic.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) throws IOException {
31 tp = t;
32 offset = o;
33 }
34
35 final boolean next() throws IOException { // 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 {
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 {
59 count = tp.freq(); // read first pos
60 nextPosition();
61 }
62
63 final boolean nextPosition() throws IOException {
64 if (count-- > 0) { // read subsequent pos's
65 position = tp.nextPosition() - offset;
66 return true;
67 } else
68 return false;
69 }
70 }
|