final String[] metaTags = ArrayUtils.parseCommaDelimitedString(srcIndex1.getIndexProperty("index.meta.key-names", "docno"));
final int[] metaTagLengths = ArrayUtils.parseCommaDelimitedInts(srcIndex1.getIndexProperty("index.meta.value-lengths", "20"));
final String[] metaReverseTags = MetaReverse
? ArrayUtils.parseCommaDelimitedString(srcIndex1.getIndexProperty("index.meta.reverse-key-names", "docno"))
: new String[0];
final MetaIndexBuilder metaBuilder = new CompressingMetaIndexBuilder(destIndex, metaTags, metaTagLengths, metaReverseTags);
if (! srcIndex1.getIndexProperty("index.meta.key-names", "docno").equals(srcIndex2.getIndexProperty("index.meta.key-names", "docno")))
{
throw new Error("Meta fields in source indices must match");
}
final BitIndexPointer emptyPointer = new SimpleBitIndexPointer();
final int srcFieldCount1 = srcIndex1.getIntIndexProperty("index.direct.fields.count", 0);
final int srcFieldCount2 = srcIndex1.getIntIndexProperty("index.direct.fields.count", 0);
if (srcFieldCount1 != srcFieldCount2)
{
throw new Error("FieldCounts in source indices must match");
}
final int fieldCount = srcFieldCount1;
for(String property : new String[] {"index.direct.fields.names","index.direct.fields.count" } )
{
destIndex.setIndexProperty(property, srcIndex1.getIndexProperty(property, null));
}
DirectInvertedOutputStream dfOutput = null;
try{
dfOutput =
(fieldCount > 0 ? fieldDirectFileOutputStreamClass : directFileOutputStreamClass)
.getConstructor(String.class)
.newInstance(destIndex.getPath() + ApplicationSetup.FILE_SEPARATOR +
destIndex.getPrefix() + ".direct" + BitIn.USUAL_EXTENSION);
} catch (Exception e) {
logger.error("Couldn't create specified DirectInvertedOutputStream", e);
return;
}
final Iterator<DocumentIndexEntry> docidInput1 = (Iterator<DocumentIndexEntry>)srcIndex1.getIndexStructureInputStream("document");
final PostingIndexInputStream dfInput1 = (PostingIndexInputStream)srcIndex1.getIndexStructureInputStream("direct");
final MetaIndex metaInput1 = srcIndex1.getMetaIndex();
int sourceDocid = 0;
//traversing the direct index, without any change
while(docidInput1.hasNext())
{
BitIndexPointer pointerDF = emptyPointer;
DocumentIndexEntry die = docidInput1.next();
if (die.getDocumentLength() > 0)
{
pointerDF = dfOutput.writePostings(dfInput1.next());
}
die.setBitIndexPointer(pointerDF);
docidOutput.addEntryToBuffer(die);
metaBuilder.writeDocumentEntry(metaInput1.getAllItems(sourceDocid));
sourceDocid++;
}
dfInput1.close();
metaInput1.close();
IndexUtil.close(docidInput1);
final Iterator<DocumentIndexEntry> docidInput2 = (Iterator<DocumentIndexEntry>)srcIndex2.getIndexStructureInputStream("document");
final PostingIndexInputStream dfInput2 = (PostingIndexInputStream)srcIndex2.getIndexStructureInputStream("direct");
final MetaIndex metaInput2 = srcIndex2.getMetaIndex();
sourceDocid = 0;
while (docidInput2.hasNext())
{
DocumentIndexEntry die = docidInput2.next();
BitIndexPointer pointerDF = emptyPointer;
if (die.getDocumentLength() > 0)
{
final IterablePosting postings = dfInput2.next();
List<Posting> postingList = new ArrayList<Posting>();
while(postings.next() != IterablePosting.EOL)
{
final Posting p = postings.asWritablePosting();
p.setId(termcodeHashmap.get(postings.getId()));
postingList.add(p);
}
Collections.sort(postingList, new PostingIdComparator());
pointerDF = dfOutput.writePostings(postingList.iterator());
}
die.setBitIndexPointer(pointerDF);
docidOutput.addEntryToBuffer(die);
metaBuilder.writeDocumentEntry(metaInput2.getAllItems(sourceDocid));
sourceDocid++;
}
dfInput2.close();
IndexUtil.close(docidInput2);
metaInput2.close();
metaBuilder.close();
dfOutput.close();
docidOutput.finishedCollections();
docidOutput.close();
destIndex.addIndexStructure(