add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / src / java / org / apache / lucene / index / SegmentMergeInfo.java
1 package org.apache.lucene.index;
2
3 /**
4  * Licensed to the Apache Software Foundation (ASF) under one or more
5  * contributor license agreements.  See the NOTICE file distributed with
6  * this work for additional information regarding copyright ownership.
7  * The ASF licenses this file to You under the Apache License, Version 2.0
8  * (the "License"); you may not use this file except in compliance with
9  * the License.  You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 import java.io.IOException;
21
22 import org.apache.lucene.index.PayloadProcessorProvider.DirPayloadProcessor;
23
24 final class SegmentMergeInfo {
25   Term term;
26   int base;
27   int ord;  // the position of the segment in a MultiReader
28   TermEnum termEnum;
29   IndexReader reader;
30   int delCount;
31   private TermPositions postings;  // use getPositions()
32   private int[] docMap;  // use getDocMap()
33   DirPayloadProcessor dirPayloadProcessor;
34   
35   SegmentMergeInfo(int b, TermEnum te, IndexReader r)
36     throws IOException {
37     base = b;
38     reader = r;
39     termEnum = te;
40     term = te.term();
41   }
42
43   // maps around deleted docs
44   int[] getDocMap() {
45     if (docMap == null) {
46       delCount = 0;
47       // build array which maps document numbers around deletions 
48       if (reader.hasDeletions()) {
49         int maxDoc = reader.maxDoc();
50         docMap = new int[maxDoc];
51         int j = 0;
52         for (int i = 0; i < maxDoc; i++) {
53           if (reader.isDeleted(i)) {
54             delCount++;
55             docMap[i] = -1;
56           } else
57             docMap[i] = j++;
58         }
59       }
60     }
61     return docMap;
62   }
63
64   TermPositions getPositions() throws IOException {
65     if (postings == null) {
66       postings = reader.termPositions();
67     }
68     return postings;
69   }
70
71   final boolean next() throws IOException {
72     if (termEnum.next()) {
73       term = termEnum.term();
74       return true;
75     } else {
76       term = null;
77       return false;
78     }
79   }
80
81   final void close() throws IOException {
82     try {
83       termEnum.close();
84     } finally {
85       if (postings != null) {
86         postings.close();
87       }
88     }
89   }
90 }
91