Does Lucene.Net manage multiple threads accessing the same index, one indexing while the other is searching? Does Lucene.Net manage multiple threads accessing the same index, one indexing while the other is searching? asp.net asp.net

Does Lucene.Net manage multiple threads accessing the same index, one indexing while the other is searching?


According to this page,

Indexing and searching are not only thread safe, but process safe. What this means is that:

  • Multiple index searchers can read the lucene index files at the same time.
  • An index writer or reader can edit the lucene index files while searches are ongoing
  • Multiple index writers or readers can try to edit the lucene index files at the same time (it's important for the index writer/reader to be closed so it will release the file lock). However, the query parser is not thread safe, so each thread using the index should have its own query parser.

The index writer however, is thread safe, so you can update the index while people are searching it. However, you then have to make sure that the threads with open index searchers close them and open new ones, to get the newly updated data.


You may have issues, if your indexing thread is creating a new document which results in merging of some index segments, then the merged segments will be deleted and new segment will be created. The problem is that your index searcher loaded up all the segments when it was opened, such that is has "pointers" to those segments which existed when it was opened. Now if the index writer does a segment merge and deletes a segment, your index searcher will still think that segment file exists and will fail with a "file not found error". What you really need to do is seperate your writable index from your searchable index, by using SOLR or doing your own index snapshot replication similar to what SOLR does. I have build very similar system to SOLR using .NET and Lucene.NET on Windows, using NTFS hard-links to make efficient snapshot replication. I can give you more info if you are interested.


You don't have a problem with that so much as managing concurrent writes to the index. I've had an easier path going with SOLR, which abstracts most of those differences away for me since it runs as a server.