Advice on architecture using Lucene?
I just want to know if I am on the right track with how I should architect 开发者_如何学编程my Lucene context in my application:
- Create a singleton class that will create an instance of the writer.
- Construct a reader each time the index needs to be read.
- Check the reader.IsCurrent() to determine if there are updates. 3a. If there are updates get the reader from the IndexWriter to use NRT.
- Commit any changes with regards to some threshold and reset the reader.
Let me know if I am on the right track. There is so much information about how to read and write, but not enough about using NRT and when to make commits properly.
You are mostly on the right path, but in fact, you can share a single instance of your reader/searcher in all the application without constructing it.
Try to have an index reader/writer factory if you have multiple indexes to manage them and if you can afford it, try to keep in the same application the reader and the writer, so you can benefit of the NRT feature of Lucene.NET.
Also, check this wiki for NRT advices:
http://wiki.apache.org/lucene-java/NearRealtimeSearch
I have been using almost the same exact architecture for awhile now, and I have found it to work fine. Instead of getting the reader from IndexWriter in step 3a, try using IndexReader.Reopen(). And in step 4, you can simply call Reopen() whenever IsCurrent() is false.
精彩评论