'Lucene indexes are getting deleted while adding a document

I am using Lucene.Net.

On some clients' machines all the indexes are getting deleted when we are trying to add a new document.

Process:

  1. Check if document already exists
  2. If Exists delete
  3. Else add a new document

Say I had 2000 indexes, now adding new one, it deletes all the indexed documents and just keeps the one which we have added recently. However, a few times it also deletes that.

It is only happening on a few customers' machines and we are also not able to reproduce on our environment.

var dir = new DirectoryInfo(_reportIndexDirectory);
 _directory = FSDirectory.Open(dir);
 _ireader = IndexReader.Open(_directory, true);

_iwriter = new IndexWriter(_directory, _analyzer, (!dir.Exists ||     dir.GetFiles().Length == 0) ? true : false, IndexWriter.MaxFieldLength.LIMITED);
 _iwriter.SetMaxFieldLength(25000);
 _iwriter.SetSimilarity(_similarityOne);
 _iwriter.SetRAMBufferSizeMB(900);


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source