KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lucene > index > SegmentMergeInfo


1 package org.apache.lucene.index;
2
3 /**
4  * Copyright 2004 The Apache Software Foundation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import java.io.IOException JavaDoc;
20
21 final class SegmentMergeInfo {
22   Term term;
23   int base;
24   TermEnum termEnum;
25   IndexReader reader;
26   private TermPositions postings; // use getPositions()
27
private int[] docMap; // use getDocMap()
28

29   SegmentMergeInfo(int b, TermEnum te, IndexReader r)
30     throws IOException JavaDoc {
31     base = b;
32     reader = r;
33     termEnum = te;
34     term = te.term();
35   }
36
37   // maps around deleted docs
38
int[] getDocMap() {
39     if (docMap == null) {
40     // build array which maps document numbers around deletions
41
if (reader.hasDeletions()) {
42       int maxDoc = reader.maxDoc();
43       docMap = new int[maxDoc];
44       int j = 0;
45       for (int i = 0; i < maxDoc; i++) {
46         if (reader.isDeleted(i))
47           docMap[i] = -1;
48         else
49           docMap[i] = j++;
50       }
51     }
52   }
53     return docMap;
54   }
55
56   TermPositions getPositions() throws IOException JavaDoc {
57     if (postings == null) {
58       postings = reader.termPositions();
59     }
60     return postings;
61   }
62
63   final boolean next() throws IOException JavaDoc {
64     if (termEnum.next()) {
65       term = termEnum.term();
66       return true;
67     } else {
68       term = null;
69       return false;
70     }
71   }
72
73   final void close() throws IOException JavaDoc {
74     termEnum.close();
75     if (postings != null) {
76     postings.close();
77   }
78 }
79 }
80
81
Popular Tags