如何合并 2 个或多个 lucene 索引并避免在最终索引中出现重复值?
今天,我正在使用此代码在索引之间进行合并:
IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_36, new StandardAnalyzer(Version.LUCENE_36));
IndexWriter writer = new IndexWriter(getFSDirectory(INDEX_DIR), iwc);
LogMergePolicy logMerge = new LogMergePolicy() {
@Override
protected long size(SegmentInfo arg0) throws IOException {
return 0;
}
};
logMerge.setMergeFactor(1000);
iwc.setRAMBufferSizeMB(50);
Directory indexes[] = new Directory[INDEXES_DIR.size()];
for (int i = 0; i < INDEXES_DIR.size(); i++) {
Directory d = FSDirectory.open(new File(INDEXES_DIR.get(i)).getAbsoluteFile());
System.out.println("Adding: " + INDEXES_DIR.get(i));
indexes[i] = d;
}
System.out.print("Merging added indexes...");
writer.addIndexes(indexes);
System.out.println("done");