当前位置: 首页>>代码示例>>C#>>正文


C# IndexSearcher.Dispose方法代码示例

本文整理汇总了C#中Lucene.Net.Search.IndexSearcher.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# IndexSearcher.Dispose方法的具体用法?C# IndexSearcher.Dispose怎么用?C# IndexSearcher.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lucene.Net.Search.IndexSearcher的用法示例。


在下文中一共展示了IndexSearcher.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

        public static ICollection<SearchResult> Execute(string query)
        {
            ICollection<SearchResult> searchResults = new List<SearchResult>();

            string directoryPath = AppDomain.CurrentDomain.BaseDirectory + @"\App_Data\LuceneIndexes";
            var directory = FSDirectory.Open(directoryPath);
            var analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);

            var parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "SearchBody", analyzer);
            Query searchQuery = parser.Parse(query + "*");

            IndexSearcher searcher = new IndexSearcher(directory);
            TopDocs hits = searcher.Search(searchQuery, 200);
            int results = hits.ScoreDocs.Length;
            for (int i = 0; i < results; i++)
            {
                Document doc = searcher.Doc(hits.ScoreDocs[i].Doc);
                var searchResult = new SearchResult();
                searchResult.EntityId = int.Parse(doc.Get("EntityId"));
                searchResult.EntityTypeName = doc.Get("EntityTypeName");
                searchResult.SearchTitle = doc.Get("SearchTitle");
                searchResult.SearchBody = doc.Get("SearchBody");
                searchResults.Add(searchResult);
            }
            searcher.Dispose();
            directory.Dispose();

            return searchResults;
        }
开发者ID:szwork2013,项目名称:BoiPlt,代码行数:29,代码来源:FullTextSearch.cs

示例2: _search

		// main search method
		private static IEnumerable<SampleData> _search(string searchQuery, string searchField = "") {
			// validation
			if (string.IsNullOrEmpty(searchQuery.Replace("*", "").Replace("?", ""))) return new List<SampleData>();

			// set up lucene searcher
			using (var searcher = new IndexSearcher(_directory, false)) {
				var hits_limit = 1000;
				var analyzer = new StandardAnalyzer(Version.LUCENE_29);

				// search by single field
				if (!string.IsNullOrEmpty(searchField)) {
					var parser = new QueryParser(Version.LUCENE_29, searchField, analyzer);
					var query = parseQuery(searchQuery, parser);
					var hits = searcher.Search(query, hits_limit).ScoreDocs;
					var results = _mapLuceneToDataList(hits, searcher);
					analyzer.Close();
					searcher.Close();
					searcher.Dispose();
					return results;
				}
				// search by multiple fields (ordered by RELEVANCE)
				else {
					var parser = new MultiFieldQueryParser
						(Version.LUCENE_29, new[] {"Id", "Name", "Description"}, analyzer);
					var query = parseQuery(searchQuery, parser);
					var hits = searcher.Search(query, null, hits_limit, Sort.INDEXORDER).ScoreDocs;
					var results = _mapLuceneToDataList(hits, searcher);
					analyzer.Close();
					searcher.Close();
					searcher.Dispose();
					return results;
				}
			}
		}
开发者ID:CelticHarp,项目名称:Lucene.Net-search-MVC-sample-site,代码行数:35,代码来源:LuceneSearch.cs

示例3: searchLucene

        public Data searchLucene(Data data)
        {
            Account_lg account = new Account_lg();
            List<string> item = new List<string>();
            Lucene.Net.Store.Directory directory = FSDirectory.Open(new DirectoryInfo("C:\\Visual Studio 2010\\Transaction" + "\\LuceneIndex"));
            var analyzer = new StandardAnalyzer(Version.LUCENE_29);
            IndexReader reader = IndexReader.Open(directory, true);
            IndexSearcher searcher = new IndexSearcher(reader);

            MultiFieldQueryParser parser = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_29, new string[] { "name", "username" }, analyzer);  //search for multifield
            Query query = parser.Parse((data.getString("search")) + "*"); //cant search blank text with wildcard as first character

            TopScoreDocCollector collector = TopScoreDocCollector.Create(1000, true);
            searcher.Search(query, collector);
            ScoreDoc[] hits = collector.TopDocs().ScoreDocs;
            int count = hits.Length;

            for (int i = 0; i < count; i++)
            {
                int docId = hits[i].Doc;
                float score = hits[i].Score;

                Document doc = searcher.Doc(docId);

                string id = doc.Get("id");
                item.Add(id);
            }
            Data list = account.selectUser(data, item.ToArray());
            reader.Dispose();
            searcher.Dispose();

            return list;
        }
开发者ID:hyori7,项目名称:AccountTransaction,代码行数:33,代码来源:Lucene_lg.cs

示例4: _search

        private static IEnumerable<CustomerId> _search(string searchQuery)
        {
            // validation
            if (string.IsNullOrEmpty(searchQuery.Replace("*", "").Replace("?", ""))) return new List<CustomerId>();

            // set up lucene searcher
            using (var searcher = new IndexSearcher(_directory, false))
            {
                var hits_limit = 1000;
                var analyzer = new StandardAnalyzer(Version.LUCENE_29);

                {
                    //var query = new TermQuery(new Term("CustomerName", searchQuery));
                    var query = new BooleanQuery();
                    query.Add(new TermQuery(new Term("CustomerName", searchQuery)), Occur.MUST);
                    var hits = searcher.Search(query, hits_limit).ScoreDocs;
                    var results = _mapLuceneToDataList(hits, searcher);

                    analyzer.Close();
                    searcher.Dispose();
                    return results;
                }
                
            }
        }
开发者ID:jcwrequests,项目名称:Learning.Lucene.NET,代码行数:25,代码来源:CustomerIndexService.cs

示例5: _search

        private static IEnumerable<LuceneSearchEO> _search(LuceneSearchType searchType, string searchQuery, string searchField = "")
        {
            // validation
            if (string.IsNullOrEmpty(searchQuery.Replace("*", "").Replace("?", ""))) return new List<LuceneSearchEO>();

            // set up lucene searcher
            using (var searcher = new IndexSearcher(getFSDirectory(searchType), false))
            {
                var hits_limit = 20;
                var analyzer = new StandardAnalyzer(Version.LUCENE_30);

                // search by single field
                if (!string.IsNullOrEmpty(searchField))
                {
                    var parser = new QueryParser(Version.LUCENE_30, searchField, analyzer);
                    var query = parseQuery(searchQuery, parser);
                    var hits = searcher.Search(query, hits_limit).ScoreDocs;
                    var results = _mapLuceneToDataList(hits, searcher);
                    analyzer.Close();
                    searcher.Dispose();
                    return results;
                }
                // search by multiple fields (ordered by RELEVANCE)
                else
                {
                    string[] fields = getLuceneSearchEOFields();
                    var parser = new MultiFieldQueryParser
                        (Version.LUCENE_30, fields, analyzer);
                    var query = parseQuery(searchQuery, parser);
                    var hits = searcher.Search(query, null, hits_limit, Sort.INDEXORDER).ScoreDocs;
                    var results = _mapLuceneToDataList(hits, searcher);
                    analyzer.Close();
                    searcher.Dispose();
                    return results;
                }
            }
        }
开发者ID:blox-ir,项目名称:BLOXLuceneManager,代码行数:37,代码来源:LuceneSearch.cs

示例6: SearchLucene

 public static List<string> SearchLucene(string searchQuery)
 {
     var directory = FSDirectory.Open(new DirectoryInfo("C:\\rm_index"));
     using (var searcher = new IndexSearcher(directory, false))
     {
         var analyzer = new StandardAnalyzer(Version.LUCENE_30);
         var parser = new QueryParser(Version.LUCENE_30, "DIRECCION_FINAL", analyzer);
         var query = ParseQuery(searchQuery, parser);
         var hits = searcher.Search(query, hits_limit).ScoreDocs;
         var results = hits.Select(hit => MapLuceneDocumentToData(searcher.Doc(hit.Doc))).ToList();
         analyzer.Close();
         searcher.Dispose();
         return results;
     }
 }
开发者ID:jzuleta,项目名称:ReclamosMoviles,代码行数:15,代码来源:LuceneAction.cs

示例7: getClanciByTag

        public static List<Post> getClanciByTag(int TAGID)
        {
            Directory directoryPronadjeniClanciTagovi = Data.Lucene.Indexing.GetDirectoryClanciTagovi();
            Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_30);
            IndexReader indexReader = IndexReader.Open(directoryPronadjeniClanciTagovi, true);
            Searcher searcher = new IndexSearcher(indexReader);

            //var queryParser = new QueryParser(Version.LUCENE_30, "Naslov", analyzer);
            var queryParser = new MultiFieldQueryParser(Version.LUCENE_30, new[] { "PostID", "TagID", "DatumKreiranja" }, analyzer);
            var query = queryParser.Parse(Convert.ToString(TAGID)); // Rastavljanje rečenice na rijeci

            TopDocs pronadjeno = searcher.Search(query, indexReader.MaxDoc);
            List<Post> postovi = new List<Post>();

            if (pronadjeno != null)
            {
                var hits = pronadjeno.ScoreDocs;
                foreach (var hit in hits)
                {
                    var documentFromSearcher = searcher.Doc(hit.Doc);
                    using (TriglavBL temp = new TriglavBL())
                    {
                        postovi.Add(temp.getPostByID(Convert.ToInt32(documentFromSearcher.Get("PostID"))));
                    }
                }
                searcher.Dispose();
                directoryPronadjeniClanciTagovi.Dispose();
                return postovi;
            }
            else
            {
                searcher.Dispose();
                directoryPronadjeniClanciTagovi.Dispose();
                return postovi;
            }
        }
开发者ID:fitba,项目名称:km-2013-projects-team-troglav,代码行数:36,代码来源:Pretraga.cs

示例8: GetAllIndexRecords

        // search methods
        public static IEnumerable<LuceneSearchModel> GetAllIndexRecords()
        {
            // validate search index
            if (!System.IO.Directory.EnumerateFiles(_luceneDir).Any()) return new List<LuceneSearchModel>();

            // set up lucene searcher
            var searcher = new IndexSearcher(_directory, false);
            var reader = IndexReader.Open(_directory, false);
            searcher.SetDefaultFieldSortScoring(true, true);
            var docs = new List<Document>();
            var term = reader.TermDocs();
            while (term.Next()) docs.Add(searcher.Doc(term.Doc));
            reader.Dispose();
            searcher.Dispose();
            return _mapLuceneToDataList(docs);
        }
开发者ID:StefanoPireddu,项目名称:mvcforum,代码行数:17,代码来源:GoLucene.cs

示例9: GetAllIndexRecords

		// search methods
		public static IEnumerable<SampleData> GetAllIndexRecords() {
			// validate search index
			if (!System.IO.Directory.EnumerateFiles(_luceneDir).Any()) return new List<SampleData>();

			// set up lucene searcher
			var searcher = new IndexSearcher(_directory, false);
			var reader = IndexReader.Open(_directory, false);
			var docs = new List<Document>();
			var term = reader.TermDocs();
      // v 2.9.4: use 'term.Doc()'
      // v 3.0.3: use 'term.Doc'
			while (term.Next()) docs.Add(searcher.Doc(term.Doc));
			reader.Dispose();
			searcher.Dispose();
			return _mapLuceneToDataList(docs);
		}
开发者ID:tridipkolkata,项目名称:Lucene.Net-search-MVC-sample-site,代码行数:17,代码来源:GoLucene.cs

示例10: GetAllIndexRecords

        public static IEnumerable<LuceneSearchEO> GetAllIndexRecords(LuceneSearchType searchType)
        {
            string _luceneDir = getLuceneDirectory(searchType);
            if (!System.IO.Directory.EnumerateFiles(_luceneDir).Any()) return new List<LuceneSearchEO>();

            // set up lucene searcher
            var searcher = new IndexSearcher(getFSDirectory(searchType), false);
            var reader = IndexReader.Open(getFSDirectory(searchType), false);
            var docs = new List<Document>();
            var term = reader.TermDocs();
            // v 2.9.4: use 'term.Doc()'
            // v 3.0.3: use 'term.Doc'
            while (term.Next()) docs.Add(searcher.Doc(term.Doc));
            reader.Dispose();
            searcher.Dispose();
            return _mapLuceneToDataList(docs);
        }
开发者ID:blox-ir,项目名称:BLOXLuceneManager,代码行数:17,代码来源:LuceneSearch.cs

示例11: Search

        public DataTable Search(Analyzer analyzer, string keyword)
        {
            if (string.IsNullOrEmpty(keyword))
            {
                throw new ArgumentException("keyword");
            }

            // 计时
            Stopwatch watch = Stopwatch.StartNew();

            // 设置
            int numHits = 10;
            bool docsScoredInOrder = true;
            bool isReadOnly = true;

            // 创建Searcher
            FSDirectory fsDir = new SimpleFSDirectory(new DirectoryInfo(_indexerFolder));
            IndexSearcher indexSearcher = new IndexSearcher(IndexReader.Open(fsDir, isReadOnly));

            TopScoreDocCollector collector = TopScoreDocCollector.Create(numHits, docsScoredInOrder);
            QueryParser parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, LuceneConfig.Field_ContentByPage, analyzer);
            Query query = parser.Parse(keyword);

            indexSearcher.Search(query, collector);

            //Console.WriteLine(collector.TotalHits);
            var result = collector.TopDocs().ScoreDocs;

            DataTable dt = ConvertToDataTable(indexSearcher, result);

            // dispose IndexSearcher
            indexSearcher.Dispose();

            watch.Stop();
            WriteLog("总共耗时{0}毫秒", watch.ElapsedMilliseconds);
            WriteLog("总共找到{0}个文件", result.Count());

            return dt;
        }
开发者ID:NDChen,项目名称:MyDemoCode,代码行数:39,代码来源:SearchHelper.cs

示例12: _search

 //partially taken from http://www.codeproject.com/Articles/320219/Lucene-Net-ultra-fast-search-for-MVC-or-WebForms
 //START
 private IEnumerable<FileToIndex> _search(string keywords, out int count, string field = "")
 {
     if (string.IsNullOrEmpty(keywords.Replace("*", "").Replace("?", "")))
     {
         count = 0;
         return new List<FileToIndex>();
     }
     using (var searcher = new IndexSearcher(_directory))
     using (var analyzer = new Lucene.Net.Analysis.Ru.RussianAnalyzer(Version.LUCENE_30))
     {
         if (!string.IsNullOrEmpty(field))
         {
             var parser = new QueryParser(Version.LUCENE_30, field, analyzer);
             var queryForField = parseQuery(keywords, parser);
             var docs = searcher.Search(queryForField, 100);
             count = docs.TotalHits;
             var samples = _convertDocs(docs.ScoreDocs, searcher);
             searcher.Dispose();
             return samples;
         }
         else
         {
             var parser = new MultiFieldQueryParser
                 (Version.LUCENE_30, new[] { "Title", "Authors", "Description", "Text", "Discipline" }, analyzer);
             var queryForField = parseQuery(keywords, parser);
             var docs = searcher.Search(queryForField, null, 100, Sort.RELEVANCE);
             count = docs.TotalHits;
             var samples = _convertDocs(docs.ScoreDocs, searcher);
             searcher.Dispose();
             return samples;
         }
     }
 }
开发者ID:LebGrigori,项目名称:StudentWorksSearch,代码行数:35,代码来源:LuceneEngine.cs

示例13: Search

        public IEnumerable<string> Search(IDictionary<string, string> matches)
        {
            var results = new List<string>();
            var indexSearcher = new IndexSearcher(_directory, true);

            var booleanQuery = new BooleanQuery();

            foreach (var match in matches)
            {
                booleanQuery.Add(new TermQuery(new Term(match.Key, match.Value)), BooleanClause.Occur.MUST);    
            }

            try
            {
                var hits = indexSearcher.Search(booleanQuery);
                var numHits = hits.Length();

                for (var i = 0; i < numHits; ++i)
                {
                    var doc = hits.Doc(i);
                    var url = doc.Get("Url");
                    results.Add(url);
                }
            }
            catch (Exception ex)
            {
                Logger.Warn(ex);
            }
            finally
            {
                indexSearcher.Close();
                indexSearcher.Dispose();
            }

            return results;
        }
开发者ID:iahdevelop,项目名称:moriyama-umbraco-runtime,代码行数:36,代码来源:SearchService.cs

示例14: SearchLucene

        private static IEnumerable<BaseCollectionItem> SearchLucene(string searchQuery, string searchField = "")
        {
            // validation
            if (string.IsNullOrEmpty(searchQuery.Replace("*", "").Replace("?", ""))) return new List<BaseCollectionItem>();

            // set up lucene searcher
            using (var searcher = new IndexSearcher(LuceneService.Directory, false))
            {
                var hits_limit = 1000;
                var analyzer = new StandardAnalyzer(Version.LUCENE_30);

                // search by single field
                if (!string.IsNullOrEmpty(searchField))
                {
                    var parser = new QueryParser(Version.LUCENE_30, searchField, analyzer);
                    var query = ParseQuery(searchQuery, parser);
                    var hits = searcher.Search(query, hits_limit).ScoreDocs;
                    var results = MapLuceneToDataList(hits, searcher);
                    analyzer.Close();
                    searcher.Dispose();
                    return results;
                }
                // search by multiple fields (ordered by RELEVANCE)
                else
                {
                    var parser = new MultiFieldQueryParser
                        (Version.LUCENE_30, new[] { "Id", "TableId", "Data","ItemProcessed", "CreatedDate" }, analyzer);
                    var query = ParseQuery(searchQuery, parser);
                    var hits = searcher.Search(query, null, hits_limit, Sort.RELEVANCE).ScoreDocs;
                    var results = MapLuceneToDataList(hits, searcher);
                    analyzer.Close();
                    searcher.Dispose();
                    return results;
                }
            }
        }
开发者ID:destromas1,项目名称:Appleseed.Base.Lite,代码行数:36,代码来源:LuceneRepository.cs

示例15: GetAllIndexRecords

        private static IEnumerable<BaseCollectionItem> GetAllIndexRecords()
        {
            // validate search index
            if (!System.IO.Directory.EnumerateFiles(LuceneService.LuceneDir).Any()) return new List<BaseCollectionItem>();

            // set up lucene searcher
            var searcher = new IndexSearcher(LuceneService.Directory, false);
            var reader = IndexReader.Open(LuceneService.Directory, false);
            var docs = new List<Document>();
            var term = reader.TermDocs();
            while (term.Next()) docs.Add(searcher.Doc(term.Doc));
            reader.Dispose();
            searcher.Dispose();
            return MapLuceneToDataList(docs);
        }
开发者ID:destromas1,项目名称:Appleseed.Base.Lite,代码行数:15,代码来源:LuceneRepository.cs


注:本文中的Lucene.Net.Search.IndexSearcher.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。