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


C# IndexSearcher.Close方法代码示例

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


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

示例1: search

    public static void search(String indexDir, String q)
    {
        Directory dir = FSDriecotry.Open(new System.IO.FileInfo(indexDir));
           IndexSearcher searcher = new IndexSearcher(dir, true);
           QueryParser parser = new QueryParser("contents", new StandardAnalyzer(Version.LUCENE_CURRENT));

           Query query = parser.Parser(q);
           Lucene.Net.Saerch.TopDocs hits = searher.Search(query, 10);
           System.Console.WriteLine("Found " + hits.totalHits + " document(s) that matched query '" + q + "':");
           for (int i = 0; i < hits.scoreDocs.Length; i++) {
           ScoreDoc scoreDoc = hits.ScoreDoc[i];
           Document doc = searcher.Doc(scoreDoc.doc);
           System.Console.WriteLine(doc.Get("filename"));
           }
          searcher.Close();
    }
开发者ID:huge-data,项目名称:LuceneDemo,代码行数:16,代码来源:Searcher.cs

示例2: SearchIndex

        private void SearchIndex()
        {
            String q = "t_text1:random";
            QueryParser parser = new QueryParser(TEST_VERSION, "t_text1", a);
            Query query = parser.Parse(q);
            IndexSearcher searcher = new IndexSearcher(dir, true);
            // This scorer can return negative idf -> null fragment
            IScorer scorer = new QueryTermScorer(query, searcher.IndexReader, "t_text1");
            // This scorer doesn't use idf (patch version)
            //Scorer scorer = new QueryTermScorer( query, "t_text1" );
            Highlighter h = new Highlighter(scorer);

            TopDocs hits = searcher.Search(query, null, 10);
            for (int i = 0; i < hits.TotalHits; i++)
            {
                Document doc = searcher.Doc(hits.ScoreDocs[i].Doc);
                String result = h.GetBestFragment(a, "t_text1", doc.Get("t_text1"));
                Console.WriteLine("result:" + result);
                Assert.AreEqual(result, "more <B>random</B> words for second field");
            }
            searcher.Close();
        }
开发者ID:hanabi1224,项目名称:lucene.net,代码行数:22,代码来源:HighlighterTest.cs


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