For the current release of RSS Bandit we decided to forego our homegrown solution for providing search over a user's subscribed feeds and go with Lucene.NET. The search capabilities are pretty cool but the provided APIs leave a lot to be desired. The only major problem we encountered with Lucene.NET is that concurrency issues are commonplace. We decided to protect against this by having only one thread that modified the Lucene index since a lot of problems seemed to occur when multiple threads were trying to modify the search index.
This is where programming with Lucene.NET turns into a journey into the land of Daily WTF style proportions.
Code Taken from Lucene Examples
public void DeleteDocument(int docNum){ lock (directory) { AssureOpen(); CreateIndexReader(); indexReader.DeleteDocument(docNum); }}void CreateIndexReader(){ if (indexReader == null) { if (indexWriter != null) { indexWriter.Close(); indexWriter = null; } indexReader = IndexReader.Open(directory); }}void AddDocument(Document doc){ lock (directory) { AssureOpen(); CreateIndexWriter(); indexWriter.AddDocument(doc); }}void CreateIndexWriter(){ if (indexWriter == null) { if (indexReader != null) { indexReader.Close(); indexReader = null; } }}
public void DeleteDocument(int docNum){ lock (directory) { AssureOpen(); CreateIndexReader(); indexReader.DeleteDocument(docNum); }}
void CreateIndexReader(){ if (indexReader == null) { if (indexWriter != null) { indexWriter.Close(); indexWriter = null; } indexReader = IndexReader.Open(directory); }}
void AddDocument(Document doc){ lock (directory) { AssureOpen(); CreateIndexWriter(); indexWriter.AddDocument(doc); }}void CreateIndexWriter(){ if (indexWriter == null) { if (indexReader != null) { indexReader.Close(); indexReader = null; } }}
As lame as this is, Lucene.NET is probably the best way to add desktop search capabilities to your .NET Framework application. I've heard they've created an IndexModifier class in newer versions of the API so some of this ugliness is hidden from application developers. How anyone thought it was OK to ship with this kind of API ugliness in the first place is beyond me.