views:

1249

answers:

2

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.

+4  A: 

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.

Corey Trager
I took a quick look at your lucene code - I see:protected static Lucene.Net.Search.Searcher searcher = null;Which just sits in your app_code folder - won't there be a new instance of searcher per user logging on to your system?
Donald
Ah nevermind, static variables are shared across the application context
Donald
Isn't that a very bad idea to lock the searcher each time a search is made? If someone executes a long-running search wont everyone else be delayed until that first search is done? What exactly is the purpose of this?
SkippyFire
A: 

You could call to the readers IsCurrent() method to check if there is a new version of the index available, and if it's then reopen it. Couldn't be the best way, but is easy enough and if your requirements are not very big it will be sufficient.

Jokin