gate.creole.annic.apache.lucene.index
Class SegmentMerger

java.lang.Object
  extended by gate.creole.annic.apache.lucene.index.SegmentMerger

final class SegmentMerger
extends Object

The SegmentMerger class combines two or more Segments, represented by an IndexReader (add(gate.creole.annic.apache.lucene.index.IndexReader), into a single Segment. After adding the appropriate readers, call the merge method to combine the segments.

If the compoundFile flag is set, then the segments will be merged into a compound file.

See Also:
merge(), add(gate.creole.annic.apache.lucene.index.IndexReader)

Field Summary
private static String[] COMPOUND_EXTENSIONS
           
private  Directory directory
           
private  FieldInfos fieldInfos
           
private  OutputStream freqOutput
           
private  int lastSkipDoc
           
private  long lastSkipFreqPointer
           
private  long lastSkipProxPointer
           
private  OutputStream proxOutput
           
private  SegmentMergeQueue queue
           
private  Vector readers
           
private  String segment
           
private  RAMOutputStream skipBuffer
           
private  int skipInterval
           
private  TermInfo termInfo
           
private  TermInfosWriter termInfosWriter
           
private  boolean useCompoundFile
           
private static String[] VECTOR_EXTENSIONS
           
 
Constructor Summary
SegmentMerger(Directory dir, String name, boolean compoundFile)
           
 
Method Summary
(package private)  void add(IndexReader reader)
          Add an IndexReader to the collection of readers that are to be merged
private  int appendPostings(SegmentMergeInfo[] smis, int n)
          Process postings from multiple segments all positioned on the same term.
private  void bufferSkip(int doc)
           
(package private)  void closeReaders()
          close all IndexReaders that have been added.
private  void createCompoundFile()
           
(package private)  int merge()
          Merges the readers specified by the add(gate.creole.annic.apache.lucene.index.IndexReader) method into the directory passed to the constructor
private  int mergeFields()
           
private  void mergeNorms()
           
private  void mergeTermInfo(SegmentMergeInfo[] smis, int n)
          Merge one term found in one or more segments.
private  void mergeTermInfos()
           
private  void mergeTerms()
           
private  void mergeVectors()
          Merge the TermVectors from each of the segments into the new one.
private  void resetSkip()
           
(package private)  IndexReader segmentReader(int i)
           
private  long writeSkip()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

useCompoundFile

private boolean useCompoundFile

directory

private Directory directory

segment

private String segment

readers

private Vector readers

fieldInfos

private FieldInfos fieldInfos

COMPOUND_EXTENSIONS

private static final String[] COMPOUND_EXTENSIONS

VECTOR_EXTENSIONS

private static final String[] VECTOR_EXTENSIONS

freqOutput

private OutputStream freqOutput

proxOutput

private OutputStream proxOutput

termInfosWriter

private TermInfosWriter termInfosWriter

skipInterval

private int skipInterval

queue

private SegmentMergeQueue queue

termInfo

private final TermInfo termInfo

skipBuffer

private RAMOutputStream skipBuffer

lastSkipDoc

private int lastSkipDoc

lastSkipFreqPointer

private long lastSkipFreqPointer

lastSkipProxPointer

private long lastSkipProxPointer
Constructor Detail

SegmentMerger

SegmentMerger(Directory dir,
              String name,
              boolean compoundFile)
Parameters:
dir - The Directory to merge the other segments into
name - The name of the new segment
compoundFile - true if the new segment should use a compoundFile
Method Detail

add

final void add(IndexReader reader)
Add an IndexReader to the collection of readers that are to be merged

Parameters:
reader -

segmentReader

final IndexReader segmentReader(int i)
Parameters:
i - The index of the reader to return
Returns:
The ith reader to be merged

merge

final int merge()
         throws IOException
Merges the readers specified by the add(gate.creole.annic.apache.lucene.index.IndexReader) method into the directory passed to the constructor

Returns:
The number of documents that were merged
Throws:
IOException

closeReaders

final void closeReaders()
                 throws IOException
close all IndexReaders that have been added. Should not be called before merge().

Throws:
IOException

createCompoundFile

private final void createCompoundFile()
                               throws IOException
Throws:
IOException

mergeFields

private final int mergeFields()
                       throws IOException
Returns:
The number of documents in all of the readers
Throws:
IOException

mergeVectors

private final void mergeVectors()
                         throws IOException
Merge the TermVectors from each of the segments into the new one.

Throws:
IOException

mergeTerms

private final void mergeTerms()
                       throws IOException
Throws:
IOException

mergeTermInfos

private final void mergeTermInfos()
                           throws IOException
Throws:
IOException

mergeTermInfo

private final void mergeTermInfo(SegmentMergeInfo[] smis,
                                 int n)
                          throws IOException
Merge one term found in one or more segments. The array smis contains segments that are positioned at the same term. N is the number of cells in the array actually occupied.

Parameters:
smis - array of segments
n - number of cells in the array actually occupied
Throws:
IOException

appendPostings

private final int appendPostings(SegmentMergeInfo[] smis,
                                 int n)
                          throws IOException
Process postings from multiple segments all positioned on the same term. Writes out merged entries into freqOutput and the proxOutput streams.

Parameters:
smis - array of segments
n - number of cells in the array actually occupied
Returns:
number of documents across all segments where this term was found
Throws:
IOException

resetSkip

private void resetSkip()
                throws IOException
Throws:
IOException

bufferSkip

private void bufferSkip(int doc)
                 throws IOException
Throws:
IOException

writeSkip

private long writeSkip()
                throws IOException
Throws:
IOException

mergeNorms

private void mergeNorms()
                 throws IOException
Throws:
IOException