I'm building an ASP.NET MVC site where I plan to use Lucene.Net. I've envisioned a way to structure the usage of Lucene, but not sure whether my planned architecture is OK and efficient.
My Plan:
- On
Application_Start
event in Global.asax: I check for the existence of the index on the file system - if it doesn't exist, I create it and fill it with documents extracted it from the database. - When new content is submitted: I create an
IndexWriter
, fill up a document, write to the index, and finally dispose of theIndexWriter
.IndexWriters
are not reused, as I can't imagine a good way to do that in an ASP.NET MVC application. - When content is edited: I repeat the same process as when new content is submitted, except that I first delete the old content and then add the edits.
- When a user searches for content: I check
HttpRuntime.Cache
to see if a user has already searched for this term in the last 5 minutes - if they have, I return those results; otherwise, I create anIndexReader
, build and run a query, put the results inHttpRuntime.Cache
, return them to the user, and finally dispose of theIndexReader
. Once again,IndexReaders
aren't reused.
My Questions:
- Is that a good structure - how can I improve it?
- Are there any performance/efficiency problems I should be aware of?
- Also, is not reusing the IndexReaders and IndexWriters a huge code smell?