01: package org.apache.lucene.index;
02:
03: /**
04: * Licensed to the Apache Software Foundation (ASF) under one or more
05: * contributor license agreements. See the NOTICE file distributed with
06: * this work for additional information regarding copyright ownership.
07: * The ASF licenses this file to You under the Apache License, Version 2.0
08: * (the "License"); you may not use this file except in compliance with
09: * 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: final class SegmentMergeInfo {
23: Term term;
24: int base;
25: TermEnum termEnum;
26: IndexReader reader;
27: private TermPositions postings; // use getPositions()
28: private int[] docMap; // use getDocMap()
29:
30: SegmentMergeInfo(int b, TermEnum te, IndexReader r)
31: throws IOException {
32: base = b;
33: reader = r;
34: termEnum = te;
35: term = te.term();
36: }
37:
38: // maps around deleted docs
39: int[] getDocMap() {
40: if (docMap == null) {
41: // build array which maps document numbers around deletions
42: if (reader.hasDeletions()) {
43: int maxDoc = reader.maxDoc();
44: docMap = new int[maxDoc];
45: int j = 0;
46: for (int i = 0; i < maxDoc; i++) {
47: if (reader.isDeleted(i))
48: docMap[i] = -1;
49: else
50: docMap[i] = j++;
51: }
52: }
53: }
54: return docMap;
55: }
56:
57: TermPositions getPositions() throws IOException {
58: if (postings == null) {
59: postings = reader.termPositions();
60: }
61: return postings;
62: }
63:
64: final boolean next() throws IOException {
65: if (termEnum.next()) {
66: term = termEnum.term();
67: return true;
68: } else {
69: term = null;
70: return false;
71: }
72: }
73:
74: final void close() throws IOException {
75: termEnum.close();
76: if (postings != null) {
77: postings.close();
78: }
79: }
80: }
|