I have an issue with Lucene.net (rel 4.8.0-beta00016). I'm not quite clear on the difference between creating an index and opening it later to add documents. I've created a C# application - using framework version 4.7.2 - in which I have a method CreateIndex() written as follows:
public void CreateIndex()
{
var Dir = FSDirectory.Open(this.IndexPathName); // Property IndexPathName contains the path that contains index
var Analyzer = new StandardAnalyzer(AppLuceneVersion);
var indexConfig = new IndexWriterConfig(AppLuceneVersion, Analyzer);
this.iIndexWriter = new IndexWriter(Dir, indexConfig);
}
If, after calling CreateIndex(), I add documents to the index, everything works. The problem arises when I close the app. When I relaunch it to add more files, if I invoke CreateIndex(), the index files get overwritten.
What code do I need to implement to open an existing index for adding documents?
While there may be others, there are generally 2 common strategies for using Lucene.NET:
IndexReaderduring application use to do searches.IndexWriter. To read, you would callIndexWriter.GetReader(). And you can use the singleton instance ofIndexWriterto add/delete/update documents at runtime at the same time reads are happening.I suggest also looking at the tutorial and the demos for creating an index and searching an index to get started.