FileDocCategorySizeDatePackage
TermInfosWriter.javaAPI DocApache Lucene 1.4.35586Tue Apr 20 15:47:58 BST 2004org.apache.lucene.index

TermInfosWriter

public final class TermInfosWriter extends Object
This stores a monotonically increasing set of pairs in a Directory. A TermInfos can be written once, in order.

Fields Summary
public static final int
FORMAT
The file format version, a negative number.
private FieldInfos
fieldInfos
private org.apache.lucene.store.OutputStream
output
private Term
lastTerm
private TermInfo
lastTi
private long
size
int
indexInterval
Expert: The fraction of terms in the "dictionary" which should be stored in RAM. Smaller values use more memory, but make searching slightly faster, while larger values use less memory and make searching slightly slower. Searching is typically not dominated by dictionary lookup, so tweaking this is rarely useful.
int
skipInterval
Expert: The fraction of {@link TermDocs} entries stored in skip tables, used to accellerate {@link TermDocs#skipTo(int)}. Larger values result in smaller indexes, greater acceleration, but fewer accelerable cases, while smaller values result in bigger indexes, less acceleration and more accelerable cases. More detailed experiments would be useful here.
private long
lastIndexPointer
private boolean
isIndex
private TermInfosWriter
other
Constructors Summary
TermInfosWriter(Directory directory, String segment, FieldInfos fis)


       
         
    initialize(directory, segment, fis, false);
    other = new TermInfosWriter(directory, segment, fis, true);
    other.other = this;
  
private TermInfosWriter(Directory directory, String segment, FieldInfos fis, boolean isIndex)

    initialize(directory, segment, fis, isIndex);
  
Methods Summary
final voidadd(org.apache.lucene.index.Term term, org.apache.lucene.index.TermInfo ti)
Adds a new pair to the set. Term must be lexicographically greater than all previous Terms added. TermInfo pointers must be positive and greater than all previous.

    if (!isIndex && term.compareTo(lastTerm) <= 0)
      throw new IOException("term out of order");
    if (ti.freqPointer < lastTi.freqPointer)
      throw new IOException("freqPointer out of order");
    if (ti.proxPointer < lastTi.proxPointer)
      throw new IOException("proxPointer out of order");

    if (!isIndex && size % indexInterval == 0)
      other.add(lastTerm, lastTi);                      // add an index term

    writeTerm(term);                                    // write term
    output.writeVInt(ti.docFreq);                       // write doc freq
    output.writeVLong(ti.freqPointer - lastTi.freqPointer); // write pointers
    output.writeVLong(ti.proxPointer - lastTi.proxPointer);

    if (ti.docFreq >= skipInterval) {
      output.writeVInt(ti.skipOffset);
    }

    if (isIndex) {
      output.writeVLong(other.output.getFilePointer() - lastIndexPointer);
      lastIndexPointer = other.output.getFilePointer(); // write pointer
    }

    lastTi.set(ti);
    size++;
  
final voidclose()
Called to complete TermInfos creation.

    output.seek(4);          // write size after format
    output.writeLong(size);
    output.close();

    if (!isIndex)
      other.close();
  
private voidinitialize(org.apache.lucene.store.Directory directory, java.lang.String segment, org.apache.lucene.index.FieldInfos fis, boolean isi)

    fieldInfos = fis;
    isIndex = isi;
    output = directory.createFile(segment + (isIndex ? ".tii" : ".tis"));
    output.writeInt(FORMAT);                      // write format
    output.writeLong(0);                          // leave space for size
    output.writeInt(indexInterval);             // write indexInterval
    output.writeInt(skipInterval);              // write skipInterval
  
private final voidwriteTerm(org.apache.lucene.index.Term term)

    int start = StringHelper.stringDifference(lastTerm.text, term.text);
    int length = term.text.length() - start;

    output.writeVInt(start);                   // write shared prefix length
    output.writeVInt(length);                  // write delta length
    output.writeChars(term.text, start, length);  // write delta chars

    output.writeVInt(fieldInfos.fieldNumber(term.field)); // write field num

    lastTerm = term;