2006-09-10 Francisco Javier F. Serrador <serrador@openshine.com>
[beagle.git] / beagled / Lucene.Net / Search / PhrasePositions.cs
blob6885c8ff96f45fa3e90194e2e042db0ca9356d59
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.
16 using System;
17 using Lucene.Net.Index;
18 namespace Lucene.Net.Search
21 sealed class PhrasePositions
23 internal int doc; // current doc
24 internal int position; // position in doc
25 internal int count; // remaining pos in this doc
26 internal int offset; // position in phrase
27 internal TermPositions tp; // stream of positions
28 internal PhrasePositions next; // used to make lists
30 internal PhrasePositions(TermPositions t, int o)
32 tp = t;
33 offset = o;
36 internal bool Next()
38 // increments to next doc
39 if (!tp.Next())
41 tp.Close(); // close stream
42 doc = System.Int32.MaxValue; // sentinel value
43 return false;
45 doc = tp.Doc();
46 position = 0;
47 return true;
50 internal bool SkipTo(int target)
52 if (!tp.SkipTo(target))
54 tp.Close(); // close stream
55 doc = System.Int32.MaxValue; // sentinel value
56 return false;
58 doc = tp.Doc();
59 position = 0;
60 return true;
64 internal void FirstPosition()
66 count = tp.Freq(); // read first pos
67 NextPosition();
70 internal bool NextPosition()
72 if (count-- > 0)
74 // read subsequent pos's
75 position = tp.NextPosition() - offset;
76 return true;
78 else
79 return false;