1 package org.apache.lucene.search;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 import java.io.IOException;
21 import org.apache.lucene.index.*;
24 * Position of a term in a document that takes into account the term offset within the phrase.
26 final class PhrasePositions {
27 int doc; // current doc
28 int position; // position in doc
29 int count; // remaining pos in this doc
30 int offset; // position in phrase
31 final int ord; // unique across all PhrasePositions instances
32 TermPositions tp; // stream of positions
33 PhrasePositions next; // used to make lists
34 boolean repeats; // there's other pp for same term (e.g. query="1st word 2nd word"~1)
36 PhrasePositions(TermPositions t, int o, int ord) {
42 final boolean next() throws IOException { // increments to next doc
44 tp.close(); // close stream
45 doc = Integer.MAX_VALUE; // sentinel value
53 final boolean skipTo(int target) throws IOException {
54 if (!tp.skipTo(target)) {
55 tp.close(); // close stream
56 doc = Integer.MAX_VALUE; // sentinel value
65 final void firstPosition() throws IOException {
66 count = tp.freq(); // read first pos
71 * Go to next location of this term current document, and set
72 * <code>position</code> as <code>location - offset</code>, so that a
73 * matching exact phrase is easily identified when all PhrasePositions
74 * have exactly the same <code>position</code>.
76 final boolean nextPosition() throws IOException {
77 if (count-- > 0) { // read subsequent pos's
78 position = tp.nextPosition() - offset;