[monkeydoc] Merge/add monkeydoc to master.
[mono.git] / mcs / tools / monkeydoc / Lucene.Net / Lucene.Net / Index / SegmentMergeInfo.cs
1 /* 
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  * 
9  * http://www.apache.org/licenses/LICENSE-2.0
10  * 
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 using System;
19
20 namespace Mono.Lucene.Net.Index
21 {
22         
23         sealed class SegmentMergeInfo
24         {
25                 internal Term term;
26                 internal int base_Renamed;
27                 internal int ord; // the position of the segment in a MultiReader
28                 internal TermEnum termEnum;
29                 internal IndexReader reader;
30                 internal int delCount;
31                 private TermPositions postings; // use getPositions()
32                 private int[] docMap; // use getDocMap()
33                 
34                 internal SegmentMergeInfo(int b, TermEnum te, IndexReader r)
35                 {
36                         base_Renamed = b;
37                         reader = r;
38                         termEnum = te;
39                         term = te.Term();
40                 }
41                 
42                 // maps around deleted docs
43                 internal int[] GetDocMap()
44                 {
45                         if (docMap == null)
46                         {
47                                 delCount = 0;
48                                 // build array which maps document numbers around deletions 
49                                 if (reader.HasDeletions())
50                                 {
51                                         int maxDoc = reader.MaxDoc();
52                                         docMap = new int[maxDoc];
53                                         int j = 0;
54                                         for (int i = 0; i < maxDoc; i++)
55                                         {
56                                                 if (reader.IsDeleted(i))
57                                                 {
58                                                         delCount++;
59                                                         docMap[i] = - 1;
60                                                 }
61                                                 else
62                                                         docMap[i] = j++;
63                                         }
64                                 }
65                         }
66                         return docMap;
67                 }
68                 
69                 internal TermPositions GetPositions()
70                 {
71                         if (postings == null)
72                         {
73                                 postings = reader.TermPositions();
74                         }
75                         return postings;
76                 }
77                 
78                 internal bool Next()
79                 {
80                         if (termEnum.Next())
81                         {
82                                 term = termEnum.Term();
83                                 return true;
84                         }
85                         else
86                         {
87                                 term = null;
88                                 return false;
89                         }
90                 }
91                 
92                 internal void  Close()
93                 {
94                         termEnum.Close();
95                         if (postings != null)
96                         {
97                                 postings.Close();
98                         }
99                 }
100         }
101 }