cvsimport
[beagle.git] / beagled / Lucene.Net / Index / SegmentMergeInfo.cs
blobae82e546316d4985b430f474c0b82e5fb6b78aa0
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;
19 namespace Lucene.Net.Index
22 sealed class SegmentMergeInfo
24 internal Term term;
25 internal int base_Renamed;
26 internal TermEnum termEnum;
27 internal IndexReader reader;
28 private TermPositions postings; // use getPositions()
29 private int[] docMap; // use getDocMap()
31 internal SegmentMergeInfo(int b, TermEnum te, IndexReader r)
33 base_Renamed = b;
34 reader = r;
35 termEnum = te;
36 term = te.Term();
39 // maps around deleted docs
40 internal int[] GetDocMap()
42 if (docMap == null)
44 // build array which maps document numbers around deletions
45 if (reader.HasDeletions())
47 int maxDoc = reader.MaxDoc();
48 docMap = new int[maxDoc];
49 int j = 0;
50 for (int i = 0; i < maxDoc; i++)
52 if (reader.IsDeleted(i))
53 docMap[i] = - 1;
54 else
55 docMap[i] = j++;
59 return docMap;
62 internal TermPositions GetPositions()
64 if (postings == null)
66 postings = reader.TermPositions();
68 return postings;
71 internal bool Next()
73 if (termEnum.Next())
75 term = termEnum.Term();
76 return true;
78 else
80 term = null;
81 return false;
85 internal void Close()
87 termEnum.Close();
88 if (postings != null)
90 postings.Close();