作者:初来乍到1231 | 来源:互联网 | 2023-05-19 16:24
above3.2versionthedefaultmergepolicyisusedtriedmergepolicysoifyouwantusesetMergeFactor
above 3.2 version the default mergepolicy is used triedmergepolicy
so if you want use setMergeFactor you must down the version use bellow code
Directory dir = FSDirectory.open(new File(indexPath));
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_31);
IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_31, analyzer);
// if (create) {
// // Create a new index in the directory, removing any
// // previously indexed documents:
// iwc.setOpenMode(OpenMode.CREATE);
// } else {
// // Add new documents to an existing index:
iwc.setOpenMode(OpenMode.CREATE_OR_APPEND);
MergePolicy mp=iwc.getMergePolicy();
if (mp instanceof LogMergePolicy)
{
LogMergePolicy lmp=(LogMergePolicy) mp;
lmp.setMergeFactor(20);
System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
}
// }
// Optional: for better indexing performance, if you
// are indexing many documents, increase the RAM
// buffer. But if you do this, increase the max heap
// size to the JVM (eg add -Xmx512m or -Xmx1g):
//
// iwc.setRAMBufferSizeMB(256.0);
IndexWriter writer = new IndexWriter(dir, iwc);
// writer.setMergeFactor(2);
// writer.deleteAll();