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


C# IndexWriter.DeleteDocuments方法代码示例

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


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

示例1: TestSparseIndex

        public virtual void TestSparseIndex()
        {
            Directory dir = NewDirectory();
            IndexWriter writer = new IndexWriter(dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())));

            for (int d = -20; d <= 20; d++)
            {
                Document doc = new Document();
                doc.Add(NewStringField("id", Convert.ToString(d), Field.Store.NO));
                doc.Add(NewStringField("body", "body", Field.Store.NO));
                writer.AddDocument(doc);
            }

            writer.ForceMerge(1);
            writer.DeleteDocuments(new Term("id", "0"));
            writer.Dispose();

            IndexReader reader = DirectoryReader.Open(dir);
            IndexSearcher search = NewSearcher(reader);
            Assert.IsTrue(reader.HasDeletions);

            ScoreDoc[] result;
            Query q = new TermQuery(new Term("body", "body"));

            result = search.Search(q, FieldCacheRangeFilter.NewByteRange("id", (sbyte?)-20, (sbyte?)20, T, T), 100).ScoreDocs;
            Assert.AreEqual(40, result.Length, "find all");

            result = search.Search(q, FieldCacheRangeFilter.NewByteRange("id", (sbyte?)0, (sbyte?)20, T, T), 100).ScoreDocs;
            Assert.AreEqual(20, result.Length, "find all");

            result = search.Search(q, FieldCacheRangeFilter.NewByteRange("id", (sbyte?)-20, (sbyte?)0, T, T), 100).ScoreDocs;
            Assert.AreEqual(20, result.Length, "find all");

            result = search.Search(q, FieldCacheRangeFilter.NewByteRange("id", (sbyte?)10, (sbyte?)20, T, T), 100).ScoreDocs;
            Assert.AreEqual(11, result.Length, "find all");

            result = search.Search(q, FieldCacheRangeFilter.NewByteRange("id", (sbyte?)-20, (sbyte?)-10, T, T), 100).ScoreDocs;
            Assert.AreEqual(11, result.Length, "find all");
            reader.Dispose();
            dir.Dispose();
        }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:41,代码来源:TestFieldCacheRangeFilter.cs

示例2: TestSetBufferSize

        public virtual void TestSetBufferSize()
        {
            //File indexDir = CreateTempDir("testSetBufferSize");
            var indexDir = new DirectoryInfo(Path.Combine(AppSettings.Get("tempDir", ""), "testSetBufferSize"));
            try
            {
                using (MockFSDirectory dir = new MockFSDirectory(indexDir, Random()))
                {
                    using (IndexWriter writer = new IndexWriter(dir,
                        (new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))).SetOpenMode(
                            IndexWriterConfig.OpenMode_e.CREATE).SetMergePolicy(NewLogMergePolicy(false))))
                    {
                        for (int i = 0; i < 37; i++)
                        {
                            var doc = new Document();
                            doc.Add(NewTextField("content", "aaa bbb ccc ddd" + i, Field.Store.YES));
                            doc.Add(NewTextField("id", "" + i, Field.Store.YES));
                            writer.AddDocument(doc);
                        }

                        dir.AllIndexInputs.Clear();
                        dir.TweakBufferSizes();
                        writer.DeleteDocuments(new Term("id", "0"));

                        var aaa = new Term("content", "aaa");
                        var bbb = new Term("content", "bbb");
                        
                        IndexSearcher searcher;
                        ScoreDoc[] hits;
                        using (var reader = DirectoryReader.Open(writer, true))
                        {
                            searcher = NewSearcher(reader);
                            hits = searcher.Search(new TermQuery(bbb), null, 1000).ScoreDocs;
                            dir.TweakBufferSizes();
                            Assert.AreEqual(36, hits.Length);
                        }

                        dir.TweakBufferSizes();
                        writer.DeleteDocuments(new Term("id", "4"));
                        using (var reader = DirectoryReader.Open(writer, true))
                        {
                            searcher = NewSearcher(reader);

                            hits = searcher.Search(new TermQuery(bbb), null, 1000).ScoreDocs;
                            dir.TweakBufferSizes();
                            Assert.AreEqual(35, hits.Length);
                            dir.TweakBufferSizes();
                            hits = searcher.Search(new TermQuery(new Term("id", "33")), null, 1000).ScoreDocs;
                            dir.TweakBufferSizes();
                            Assert.AreEqual(1, hits.Length);
                            hits = searcher.Search(new TermQuery(aaa), null, 1000).ScoreDocs;
                            dir.TweakBufferSizes();
                            Assert.AreEqual(35, hits.Length);
                        }
                    }
                }
            }
            finally
            {
                System.IO.Directory.Delete(indexDir.FullName, true);
            }
        }
开发者ID:joyanta,项目名称:lucene.net,代码行数:62,代码来源:TestBufferedIndexInput.cs

示例3: TestSetBufferSize

        public virtual void TestSetBufferSize()
        {
            var indexDir = CreateTempDir("testSetBufferSize");
            var dir = new MockFSDirectory(indexDir, Random());
            try
            {
                var writer = new IndexWriter(
                    dir,
                    new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))
                        .SetOpenMode(IndexWriterConfig.OpenMode_e.CREATE)
                        .SetMergePolicy(NewLogMergePolicy(false)));
                    
                for (int i = 0; i < 37; i++)
                {
                    var doc = new Document();
                    doc.Add(NewTextField("content", "aaa bbb ccc ddd" + i, Field.Store.YES));
                    doc.Add(NewTextField("id", "" + i, Field.Store.YES));
                    writer.AddDocument(doc);
                }

                dir.AllIndexInputs.Clear();

                IndexReader reader = DirectoryReader.Open(writer, true);
                var aaa = new Term("content", "aaa");
                var bbb = new Term("content", "bbb");
                reader.Dispose();

                dir.TweakBufferSizes();
                writer.DeleteDocuments(new Term("id", "0"));
                reader = DirectoryReader.Open(writer, true);
                var searcher = NewSearcher(reader);
                var hits = searcher.Search(new TermQuery(bbb), null, 1000).ScoreDocs;
                dir.TweakBufferSizes();
                Assert.AreEqual(36, hits.Length);

                reader.Dispose();

                dir.TweakBufferSizes();
                writer.DeleteDocuments(new Term("id", "4"));
                reader = DirectoryReader.Open(writer, true);
                searcher = NewSearcher(reader);

                hits = searcher.Search(new TermQuery(bbb), null, 1000).ScoreDocs;
                dir.TweakBufferSizes();
                Assert.AreEqual(35, hits.Length);
                dir.TweakBufferSizes();
                hits = searcher.Search(new TermQuery(new Term("id", "33")), null, 1000).ScoreDocs;
                dir.TweakBufferSizes();
                Assert.AreEqual(1, hits.Length);
                hits = searcher.Search(new TermQuery(aaa), null, 1000).ScoreDocs;
                dir.TweakBufferSizes();
                Assert.AreEqual(35, hits.Length);
                writer.Dispose();
                reader.Dispose();
            }
            finally
            {
                indexDir.Delete(true);
            }
        }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:60,代码来源:TestBufferedIndexInput.cs


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