C# – Lucene.net with IndexSearcher/IndexWriter in a Web Application

asp.netclucenelucene.net

I'm currently running Lucene.net in a web application and am wondering about the best method, performance-wise.

I currently have it set up so that all index writes get processed together in a scheduled process, along with optimizing the index.

However for searching – I'm currently opening and closing the searcher per search, which I know isn't ideal.

What do you think would be the best approach in this situation?

I'll need to close and reopen the index searcher once the updates/optimization is processed so the scheduled process (which is a windows console app) needs to communicate it's finished to the web application.

Best Answer

I just integrated Lucene.NET into BugTracker.NET. I'm not sure that what I did is the best, but it seems to be working well.

I create the index at app startup.

I create a searcher and keep it around so that the index isn't reloaded with each search. All threads share the same searcher. When the searcher searches, it grabs a lock.

Meanwhile, I have an IndexWriter that updates the index when there is a data change. It is just changing a little bit so it does its task quick. When it runs, it grabs the same lock, destroys the searcher, updates the index, and the re-recreates the searcher. The new searcher stays around until the next update of the index. The searcher always is working with an up-to-date index.

You can get the BugTracker.NET source and look at the files my_lucene.cs and search_text.aspx. It's all in those two files, and there isn't that much code.

Related Topic