org.apache.lucene.index
final class: SegmentMerger [javadoc |
source]
java.lang.Object
org.apache.lucene.index.SegmentMerger
The SegmentMerger class combines two or more Segments, represented by an IndexReader (
#add ,
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.
| Field Summary |
|---|
| static final byte[] | NORMS_HEADER | norms header placeholder |
| Constructor: |
SegmentMerger(Directory dir,
String name) {
directory = dir;
segment = name;
}
This ctor used only by test code. Parameters:
dir - The Directory to merge the other segments into
name - The name of the new segment
|
SegmentMerger(IndexWriter writer,
String name,
MergePolicy.OneMerge merge) {
directory = writer.getDirectory();
segment = name;
if (merge != null)
checkAbort = new CheckAbort(merge, directory);
termIndexInterval = writer.getTermIndexInterval();
}
|
| Method from org.apache.lucene.index.SegmentMerger Detail: |
final void add(IndexReader reader) {
readers.addElement(reader);
}
Add an IndexReader to the collection of readers that are to be merged |
final void closeReaders() throws IOException {
for (int i = 0; i < readers.size(); i++) { // close readers
IndexReader reader = (IndexReader) readers.elementAt(i);
reader.close();
}
}
close all IndexReaders that have been added.
Should not be called before merge(). |
final Vector createCompoundFile(String fileName) throws IOException {
CompoundFileWriter cfsWriter =
new CompoundFileWriter(directory, fileName, checkAbort);
Vector files =
new Vector(IndexFileNames.COMPOUND_EXTENSIONS.length + 1);
// Basic files
for (int i = 0; i < IndexFileNames.COMPOUND_EXTENSIONS.length; i++) {
String ext = IndexFileNames.COMPOUND_EXTENSIONS[i];
if (mergeDocStores || (!ext.equals(IndexFileNames.FIELDS_EXTENSION) &&
!ext.equals(IndexFileNames.FIELDS_INDEX_EXTENSION)))
files.add(segment + "." + ext);
}
// Fieldable norm files
for (int i = 0; i < fieldInfos.size(); i++) {
FieldInfo fi = fieldInfos.fieldInfo(i);
if (fi.isIndexed && !fi.omitNorms) {
files.add(segment + "." + IndexFileNames.NORMS_EXTENSION);
break;
}
}
// Vector files
if (fieldInfos.hasVectors() && mergeDocStores) {
for (int i = 0; i < IndexFileNames.VECTOR_EXTENSIONS.length; i++) {
files.add(segment + "." + IndexFileNames.VECTOR_EXTENSIONS[i]);
}
}
// Now merge all added files
Iterator it = files.iterator();
while (it.hasNext()) {
cfsWriter.addFile((String) it.next());
}
// Perform the merge
cfsWriter.close();
return files;
}
|
final int merge() throws IOException, CorruptIndexException {
return merge(true);
}
Merges the readers specified by the #add method into the directory passed to the constructor |
final int merge(boolean mergeDocStores) throws IOException, CorruptIndexException {
this.mergeDocStores = mergeDocStores;
// NOTE: it's important to add calls to
// checkAbort.work(...) if you make any changes to this
// method that will spend alot of time. The frequency
// of this check impacts how long
// IndexWriter.close(false) takes to actually stop the
// threads.
mergedDocs = mergeFields();
mergeTerms();
mergeNorms();
if (mergeDocStores && fieldInfos.hasVectors())
mergeVectors();
return mergedDocs;
}
Merges the readers specified by the #add method
into the directory passed to the constructor. |
final IndexReader segmentReader(int i) {
return (IndexReader) readers.elementAt(i);
}
|