1 package org.apache.lucene.index; 2 3 18 19 import java.io.IOException ; 20 import org.apache.lucene.store.IndexInput; 21 22 final class SegmentTermEnum extends TermEnum implements Cloneable { 23 private IndexInput input; 24 FieldInfos fieldInfos; 25 long size; 26 long position = -1; 27 28 private TermBuffer termBuffer = new TermBuffer(); 29 private TermBuffer prevBuffer = new TermBuffer(); 30 private TermBuffer scratch; 32 private TermInfo termInfo = new TermInfo(); 33 34 private int format; 35 private boolean isIndex = false; 36 long indexPointer = 0; 37 int indexInterval; 38 int skipInterval; 39 private int formatM1SkipInterval; 40 41 SegmentTermEnum(IndexInput i, FieldInfos fis, boolean isi) 42 throws IOException { 43 input = i; 44 fieldInfos = fis; 45 isIndex = isi; 46 47 int firstInt = input.readInt(); 48 if (firstInt >= 0) { 49 format = 0; 51 size = firstInt; 52 53 indexInterval = 128; 55 skipInterval = Integer.MAX_VALUE; 57 } else { 58 format = firstInt; 60 61 if (format < TermInfosWriter.FORMAT) 63 throw new IOException ("Unknown format version:" + format); 64 65 size = input.readLong(); 67 if(format == -1){ 68 if (!isIndex) { 69 indexInterval = input.readInt(); 70 formatM1SkipInterval = input.readInt(); 71 } 72 skipInterval = Integer.MAX_VALUE; 75 } 76 else{ 77 indexInterval = input.readInt(); 78 skipInterval = input.readInt(); 79 } 80 } 81 82 } 83 84 protected Object clone() { 85 SegmentTermEnum clone = null; 86 try { 87 clone = (SegmentTermEnum) super.clone(); 88 } catch (CloneNotSupportedException e) {} 89 90 clone.input = (IndexInput) input.clone(); 91 clone.termInfo = new TermInfo(termInfo); 92 93 clone.termBuffer = (TermBuffer)termBuffer.clone(); 94 clone.prevBuffer = (TermBuffer)prevBuffer.clone(); 95 clone.scratch = null; 96 97 return clone; 98 } 99 100 final void seek(long pointer, int p, Term t, TermInfo ti) 101 throws IOException { 102 input.seek(pointer); 103 position = p; 104 termBuffer.set(t); 105 prevBuffer.reset(); 106 termInfo.set(ti); 107 } 108 109 110 public final boolean next() throws IOException { 111 if (position++ >= size - 1) { 112 termBuffer.reset(); 113 return false; 114 } 115 116 prevBuffer.set(termBuffer); 117 termBuffer.read(input, fieldInfos); 118 119 termInfo.docFreq = input.readVInt(); termInfo.freqPointer += input.readVLong(); termInfo.proxPointer += input.readVLong(); 123 if(format == -1){ 124 if (!isIndex) { 127 if (termInfo.docFreq > formatM1SkipInterval) { 128 termInfo.skipOffset = input.readVInt(); 129 } 130 } 131 } 132 else{ 133 if (termInfo.docFreq >= skipInterval) 134 termInfo.skipOffset = input.readVInt(); 135 } 136 137 if (isIndex) 138 indexPointer += input.readVLong(); 140 return true; 141 } 142 143 144 final void scanTo(Term term) throws IOException { 145 if (scratch == null) 146 scratch = new TermBuffer(); 147 scratch.set(term); 148 while (scratch.compareTo(termBuffer) > 0 && next()) {} 149 } 150 151 153 public final Term term() { 154 return termBuffer.toTerm(); 155 } 156 157 158 final Term prev() { 159 return prevBuffer.toTerm(); 160 } 161 162 164 final TermInfo termInfo() { 165 return new TermInfo(termInfo); 166 } 167 168 170 final void termInfo(TermInfo ti) { 171 ti.set(termInfo); 172 } 173 174 176 public final int docFreq() { 177 return termInfo.docFreq; 178 } 179 180 182 final long freqPointer() { 183 return termInfo.freqPointer; 184 } 185 186 188 final long proxPointer() { 189 return termInfo.proxPointer; 190 } 191 192 193 public final void close() throws IOException { 194 input.close(); 195 } 196 } 197 | Popular Tags |