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


C# IndexWriter.close方法代码示例

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


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

示例1: TestNegativeQueryBoost

        public virtual void TestNegativeQueryBoost()
        {
            Query q = new TermQuery(new Term("foo", "bar"));
            q.Boost = -42f;
            Assert.AreEqual(-42f, q.Boost, 0.0f);

            Directory directory = newDirectory();
            try
            {
              Analyzer analyzer = new MockAnalyzer(random());
              IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);

              IndexWriter writer = new IndexWriter(directory, conf);
              try
              {
            Document d = new Document();
            d.add(newTextField("foo", "bar", Field.Store.YES));
            writer.addDocument(d);
              }
              finally
              {
            writer.close();
              }

              IndexReader reader = DirectoryReader.open(directory);
              try
              {
            IndexSearcher searcher = newSearcher(reader);

            ScoreDoc[] hits = searcher.search(q, null, 1000).scoreDocs;
            Assert.AreEqual(1, hits.Length);
            Assert.IsTrue("score is not negative: " + hits[0].score, hits[0].score < 0);

            Explanation explain = searcher.explain(q, hits[0].doc);
            Assert.AreEqual("score doesn't match explanation", hits[0].score, explain.Value, 0.001f);
            Assert.IsTrue("explain doesn't think doc is a match", explain.Match);

              }
              finally
              {
            reader.close();
              }
            }
            finally
            {
              directory.close();
            }
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:48,代码来源:TestSearch.cs

示例2: DoTestSearch

        private void DoTestSearch(Random random, PrintWriter @out, bool useCompoundFile)
        {
            Directory directory = newDirectory();
              Analyzer analyzer = new MockAnalyzer(random);
              IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);
              MergePolicy mp = conf.MergePolicy;
              mp.NoCFSRatio = useCompoundFile ? 1.0 : 0.0;
              IndexWriter writer = new IndexWriter(directory, conf);

              string[] docs = new string[] {"a b c d e", "a b c d e a b c d e", "a b c d e f g h i j", "a c e", "e c a", "a c e a c e", "a c e a b c"};
              for (int j = 0; j < docs.Length; j++)
              {
            Document d = new Document();
            d.add(newTextField("contents", docs[j], Field.Store.YES));
            d.add(newStringField("id", "" + j, Field.Store.NO));
            writer.addDocument(d);
              }
              writer.close();

              IndexReader reader = DirectoryReader.open(directory);
              IndexSearcher searcher = newSearcher(reader);

              ScoreDoc[] hits = null;

              Sort sort = new Sort(SortField.FIELD_SCORE, new SortField("id", SortField.Type.INT));

              foreach (Query query in BuildQueries())
              {
            @out.println("Query: " + query.ToString("contents"));
            if (VERBOSE)
            {
              Console.WriteLine("TEST: query=" + query);
            }

            hits = searcher.search(query, null, 1000, sort).scoreDocs;

            @out.println(hits.Length + " total results");
            for (int i = 0 ; i < hits.Length && i < 10; i++)
            {
              Document d = searcher.doc(hits[i].doc);
              @out.println(i + " " + hits[i].score + " " + d.get("contents"));
            }
              }
              reader.close();
              directory.close();
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:46,代码来源:TestSearch.cs


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