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


C# Lucene.Net.Index.IndexWriter.addDocument方法代码示例

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


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

示例1: TestPerFieldCodec

        // tests storing "id" and "field2" fields as pulsing codec,
        // whose term sort is backwards unicode code point, and
        // storing "field1" as a custom entirely-in-RAM codec
        public virtual void TestPerFieldCodec()
        {
            int NUM_DOCS = atLeast(173);
            if (VERBOSE)
            {
              Console.WriteLine("TEST: NUM_DOCS=" + NUM_DOCS);
            }

            BaseDirectoryWrapper dir = newDirectory();
            dir.CheckIndexOnClose = false; // we use a custom codec provider
            IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())).setCodec(new CustomPerFieldCodec()).setMergePolicy(newLogMergePolicy(3)));
            Document doc = new Document();
            // uses default codec:
            doc.Add(newTextField("field1", "this field uses the standard codec as the test", Field.Store.NO));
            // uses pulsing codec:
            Field field2 = newTextField("field2", "this field uses the pulsing codec as the test", Field.Store.NO);
            doc.Add(field2);

            Field idField = newStringField("id", "", Field.Store.NO);

            doc.Add(idField);
            for (int i = 0;i < NUM_DOCS;i++)
            {
              idField.StringValue = "" + i;
              w.addDocument(doc);
              if ((i + 1) % 10 == 0)
              {
            w.commit();
              }
            }
            if (VERBOSE)
            {
              Console.WriteLine("TEST: now delete id=77");
            }
            w.deleteDocuments(new Term("id", "77"));

            IndexReader r = DirectoryReader.Open(w, true);

            Assert.AreEqual(NUM_DOCS - 1, r.NumDocs());
            IndexSearcher s = newSearcher(r);
            Assert.AreEqual(NUM_DOCS - 1, s.Search(new TermQuery(new Term("field1", "standard")), 1).TotalHits);
            Assert.AreEqual(NUM_DOCS - 1, s.Search(new TermQuery(new Term("field2", "pulsing")), 1).TotalHits);
            r.Close();

            if (VERBOSE)
            {
              Console.WriteLine("\nTEST: now delete 2nd doc");
            }
            w.deleteDocuments(new Term("id", "44"));

            if (VERBOSE)
            {
              Console.WriteLine("\nTEST: now force merge");
            }
            w.forceMerge(1);
            if (VERBOSE)
            {
              Console.WriteLine("\nTEST: now open reader");
            }
            r = DirectoryReader.Open(w, true);
            Assert.AreEqual(NUM_DOCS - 2, r.MaxDoc());
            Assert.AreEqual(NUM_DOCS - 2, r.NumDocs());
            s = newSearcher(r);
            Assert.AreEqual(NUM_DOCS - 2, s.Search(new TermQuery(new Term("field1", "standard")), 1).TotalHits);
            Assert.AreEqual(NUM_DOCS - 2, s.Search(new TermQuery(new Term("field2", "pulsing")), 1).TotalHits);
            Assert.AreEqual(1, s.Search(new TermQuery(new Term("id", "76")), 1).TotalHits);
            Assert.AreEqual(0, s.Search(new TermQuery(new Term("id", "77")), 1).TotalHits);
            Assert.AreEqual(0, s.Search(new TermQuery(new Term("id", "44")), 1).TotalHits);

            if (VERBOSE)
            {
              Console.WriteLine("\nTEST: now close NRT reader");
            }
            r.Close();

            w.Dispose();

            dir.Dispose();
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:82,代码来源:TestExternalCodecs.cs


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