创建只有一个段的 Lucene 索引

Create Lucene index with only one segment

如何创建只有一个段的 Lucene 索引(不使用强制合并) 我有足够多的 RAM,所以我尝试使用 1.5GB 的缓冲区大小用于 mucj 较小的索引,最多 64-128MB,但在索引结束时仍然有 5-10 个段。 我该怎么办?

public static final double DEFAULT_RAM_BUFFER_SIZE_MB_STORE = 1536.;

...

final File file = new File(pathIndex);
final Path path = file.toPath();
final Directory index = ControlObjectsLuceneIndex.createDirectory(path, file);
final IndexWriterConfig indexWriterConfig = new IndexWriterConfig(analyzer);
indexWriterConfig.setRAMBufferSizeMB(defaultRamBufferSizeMb);
indexWriterConfig.setSimilarity(_ekspertSimilarity);
indexWriterConfig.setUseCompoundFile(false);
return new IndexWriter(index, indexWriterConfig);

A flush is triggered when there are enough added documents since the last flush. Flushing is triggered either by RAM usage of the documents (see IndexWriterConfig.setRAMBufferSizeMB(double)) or the number of added documents (see IndexWriterConfig.setMaxBufferedDocs(int)).

这意味着,如果您想防止刷新 - 您需要对这两个值都设置上限,以确保添加的文档数量和 RAM 使用率都低于您的限制。

另一种方法是在 setMaxBufferedDocssetRAMBufferSizeMB 中传递 IndexWriterConfig.DISABLE_AUTO_FLUSH 以防止由于缓冲文档的数量或 RAM 使用而触发刷新。请注意,但是您不能将两个值都设置为 DISABLE_AUTO_FLUSH 并且很可能您应该能够比 RAM

的数量更容易地计算出您的文档数量

此外,请确保您对 IndexWriter 的使用仅在单线程中(或正确同步)

来源:https://lucene.apache.org/core/7_6_0/core/org/apache/lucene/index/IndexWriter.html