コード例 #1
0
 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.
 }
コード例 #2
0
        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);
        }
コード例 #3
0
        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;
            }
        }
コード例 #4
0
ファイル: SearchIndex.cs プロジェクト: natewallace/walli
        /// <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();
            }
        }