简体   繁体   English

Lucene IndexWriter.Close()与indexWriter.Commit()

[英]Lucene IndexWriter.Close() vs indexWriter.Commit()

What is different between IndexWriter.Close() and IndexWriter.Commit() when I hava just single instance of indexWriter ? 当我只有indexWriter的一个实例时, IndexWriter.Close()IndexWriter.Commit()什么indexWriter

Note :The Data that I going to make index is very big then I can't close IndexWriter runtime. 注意 :我要创建索引的数据很大,所以我无法关闭IndexWriter运行时。

Note :I want to search in documents when data are indexing at sametime. 注意 :我想同时索引数据时搜索文档。

Commit() commits pending, buffered changes to the index (which can then be found with IndexReader() ). Commit()提交对索引的暂挂缓冲更改(然后可以通过IndexReader()找到)。 The IndexWriter can then continue to be used for more changes. 然后可以继续使用IndexWriter进行更多更改。 Close() also performs a Commit(), but additionally closes the IndexWriter. Close()还执行Commit(),但另外关闭IndexWriter。 Note that IndexWriter implements IDisposable(), and I recommend using it. 请注意,IndexWriter实现IDisposable(),我建议使用它。

By your first note, if you mean there are lots of documents to index, that's fine. 首先,如果您的意思是要索引的文档很多,那很好。 You can use the same IndexWriter for many documents without closing it. 您可以将同一IndexWriter用于许多文档,而无需关闭它。 Just loop through however many documents you want to index within the same IndexWriter using() statement. 只需遍历要使用using()语句在同一IndexWriter中建立索引的许多文档即可。

With regards to your second note, you must perform a commit() ( or close()) before your IndexWriter() changes will be seen by an IndexReader(). 关于第二个注释,您必须先执行commit()(或close()),然后IndexReader()才能看到IndexWriter()的更改。 You can always search with IndexReader(), but it will only see the index as it was since the last IndexWriter.Commit(). 您始终可以使用IndexReader()搜索,但是它只会看到自上一个IndexWriter.Commit()以来的索引。

I recommend Lucene In Action for these important details. 对于这些重要细节,我建议使用Lucene In Action。 It helped me a great deal. 它极大地帮助了我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM