1 package org.apache.lucene.index;
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 import java.io.IOException;
22 import org.apache.lucene.index.FieldInfo.IndexOptions;
23 import org.apache.lucene.index.FreqProxTermsWriterPerField.FreqProxPostingsArray;
25 // TODO FI: some of this is "generic" to TermsHash* so we
26 // should factor it out so other consumers don't have to
27 // duplicate this code
29 /** Used by DocumentsWriter to merge the postings from
30 * multiple ThreadStates when creating a segment */
31 final class FreqProxFieldMergeState {
33 final FreqProxTermsWriterPerField field;
34 final int numPostings;
35 final CharBlockPool charPool;
37 final FreqProxPostingsArray postings;
43 private int postingUpto = -1;
45 final ByteSliceReader freq = new ByteSliceReader();
46 final ByteSliceReader prox = new ByteSliceReader();
51 public FreqProxFieldMergeState(FreqProxTermsWriterPerField field) {
53 this.charPool = field.perThread.termsHashPerThread.charPool;
54 this.numPostings = field.termsHashPerField.numPostings;
55 this.termIDs = field.termsHashPerField.sortPostings();
56 this.postings = (FreqProxPostingsArray) field.termsHashPerField.postingsArray;
59 boolean nextTerm() throws IOException {
61 if (postingUpto == numPostings)
64 currentTermID = termIDs[postingUpto];
67 final int textStart = postings.textStarts[currentTermID];
68 text = charPool.buffers[textStart >> DocumentsWriter.CHAR_BLOCK_SHIFT];
69 textOffset = textStart & DocumentsWriter.CHAR_BLOCK_MASK;
71 field.termsHashPerField.initReader(freq, currentTermID, 0);
72 if (field.fieldInfo.indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS)
73 field.termsHashPerField.initReader(prox, currentTermID, 1);
75 // Should always be true
76 boolean result = nextDoc();
82 public String termText() {
83 int upto = textOffset;
84 while(text[upto] != 0xffff) {
87 return new String(text, textOffset, upto-textOffset);
90 public boolean nextDoc() throws IOException {
92 if (postings.lastDocCodes[currentTermID] != -1) {
94 docID = postings.lastDocIDs[currentTermID];
95 if (field.indexOptions != IndexOptions.DOCS_ONLY)
96 termFreq = postings.docFreqs[currentTermID];
97 postings.lastDocCodes[currentTermID] = -1;
104 final int code = freq.readVInt();
105 if (field.indexOptions == IndexOptions.DOCS_ONLY)
112 termFreq = freq.readVInt();
115 assert docID != postings.lastDocIDs[currentTermID];