protected virtual void Dispose(bool disposing) { if (disposing) { // free managed resources if (analyzer != null) { analyzer.Dispose(); } if (searcher != null) { searcher.Dispose(); } } // free native resources if there are any. }
public List <LuceneData> Search(string searchText, string searchField) { List <LuceneData> output = new List <LuceneData>(); string searchQuery = string.Empty; try { if (string.IsNullOrEmpty(searchText.Trim())) { throw new Exception("You forgot to enter something to search for..."); } searchQuery = searchText; } catch { throw; } try { // Open the IndexReader with readOnly=true. // This makes a big difference when multiple threads are sharing the same reader, // as it removes certain sources of thread contention. searcher = new Lucene.Net.Search.IndexSearcher(_directory, true); analyzer = new Lucene.Net.Analysis.Standard.StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30); output = (GetSearchResultByField(searchQuery, searchField, searcher, analyzer)); } catch { throw; } finally { analyzer.Close(); analyzer.Dispose(); searcher.Dispose(); } return(output); }
public void LuceneDispose() { if (searcher != null) { searcher.Dispose(); searcher = null; } if (reader != null) { reader.Dispose(); reader = null; } if (analyzer != null) { analyzer.Dispose(); analyzer = null; } if (direc != null) { direc.Dispose(); direc = null; } }
/// <summary> /// Dispose of this object. /// </summary> public void Dispose() { if (_writer != null) { _writer.Optimize(); _writer.Flush(true, true, true); _writer.Dispose(); } if (_searcher != null) { _searcher.Dispose(); } if (_analyzer != null) { _analyzer.Dispose(); } if (_directory != null) { _directory.Dispose(); } }