Lucene.Net  3.0.3
Lucene.Net is a port of the Lucene search engine library, written in C# and targeted at .NET runtime users.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
SegmentMergeInfo.cs
Go to the documentation of this file.
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 Lucene.Net.Index
21 {
22 
23  sealed class SegmentMergeInfo : IDisposable
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  private bool isDisposed;
35 
36  internal SegmentMergeInfo(int b, TermEnum te, IndexReader r)
37  {
38  base_Renamed = b;
39  reader = r;
40  termEnum = te;
41  term = te.Term;
42  }
43 
44  // maps around deleted docs
45  internal int[] GetDocMap()
46  {
47  if (docMap == null)
48  {
49  delCount = 0;
50  // build array which maps document numbers around deletions
51  if (reader.HasDeletions)
52  {
53  int maxDoc = reader.MaxDoc;
54  docMap = new int[maxDoc];
55  int j = 0;
56  for (int i = 0; i < maxDoc; i++)
57  {
58  if (reader.IsDeleted(i))
59  {
60  delCount++;
61  docMap[i] = - 1;
62  }
63  else
64  docMap[i] = j++;
65  }
66  }
67  }
68  return docMap;
69  }
70 
71  internal TermPositions GetPositions()
72  {
73  if (postings == null)
74  {
75  postings = reader.TermPositions();
76  }
77  return postings;
78  }
79 
80  internal bool Next()
81  {
82  if (termEnum.Next())
83  {
84  term = termEnum.Term;
85  return true;
86  }
87  else
88  {
89  term = null;
90  return false;
91  }
92  }
93 
94  public void Dispose()
95  {
96  if (isDisposed) return;
97 
98  // Move to protected method if class becomes unsealed
99  termEnum.Close();
100  if (postings != null)
101  {
102  postings.Close();
103  }
104 
105  isDisposed = true;
106  }
107  }
108 }