cvsimport
[beagle.git] / beagled / Lucene.Net / Search / PhrasePositions.cs
blobd19980c4e2b4613e7a8d743f292e1c7511591846
1 /*
2 * Copyright 2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 using System;
18 using Lucene.Net.Index;
20 namespace Lucene.Net.Search
23 sealed class PhrasePositions
25 internal int doc; // current doc
26 internal int position; // position in doc
27 internal int count; // remaining pos in this doc
28 internal int offset; // position in phrase
29 internal TermPositions tp; // stream of positions
30 internal PhrasePositions next; // used to make lists
32 internal PhrasePositions(TermPositions t, int o)
34 tp = t;
35 offset = o;
38 internal bool Next()
40 // increments to next doc
41 if (!tp.Next())
43 tp.Close(); // close stream
44 doc = System.Int32.MaxValue; // sentinel value
45 return false;
47 doc = tp.Doc();
48 position = 0;
49 return true;
52 internal bool SkipTo(int target)
54 if (!tp.SkipTo(target))
56 tp.Close(); // close stream
57 doc = System.Int32.MaxValue; // sentinel value
58 return false;
60 doc = tp.Doc();
61 position = 0;
62 return true;
66 internal void FirstPosition()
68 count = tp.Freq(); // read first pos
69 NextPosition();
72 internal bool NextPosition()
74 if (count-- > 0)
76 // read subsequent pos's
77 position = tp.NextPosition() - offset;
78 return true;
80 else
81 return false;