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


C# Lucene.Net.Index.RandomIndexWriter.DeleteDocuments方法代码示例

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


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

示例1: SetUp

        public override void SetUp()
        {
            base.SetUp();
            Dir = NewDirectory();
            FieldName = Random().NextBoolean() ? "field" : ""; // sometimes use an empty string as field name
            RandomIndexWriter writer = new RandomIndexWriter(Random(), Dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random(), MockTokenizer.KEYWORD, false)).SetMaxBufferedDocs(TestUtil.NextInt(Random(), 50, 1000)));
            List<string> terms = new List<string>();
            int num = AtLeast(200);
            for (int i = 0; i < num; i++)
            {
                Document doc = new Document();
                doc.Add(NewStringField("id", Convert.ToString(i), Field.Store.NO));
                int numTerms = Random().Next(4);
                for (int j = 0; j < numTerms; j++)
                {
                    string s = TestUtil.RandomUnicodeString(Random());
                    doc.Add(NewStringField(FieldName, s, Field.Store.NO));
                    // if the default codec doesn't support sortedset, we will uninvert at search time
                    if (DefaultCodecSupportsSortedSet())
                    {
                        doc.Add(new SortedSetDocValuesField(FieldName, new BytesRef(s)));
                    }
                    terms.Add(s);
                }
                writer.AddDocument(doc);
            }

            if (VERBOSE)
            {
                // utf16 order
                terms.Sort();
                Console.WriteLine("UTF16 order:");
                foreach (string s in terms)
                {
                    Console.WriteLine("  " + UnicodeUtil.ToHexString(s));
                }
            }

            int numDeletions = Random().Next(num / 10);
            for (int i = 0; i < numDeletions; i++)
            {
                writer.DeleteDocuments(new Term("id", Convert.ToString(Random().Next(num))));
            }

            Reader = writer.Reader;
            Searcher1 = NewSearcher(Reader);
            Searcher2 = NewSearcher(Reader);
            writer.Dispose();
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:49,代码来源:TestDocTermOrdsRangeFilter.cs

示例2: BuildIndex

 private int[] BuildIndex(RandomIndexWriter writer, int docs)
 {
     int[] docStates = new int[docs];
     for (int i = 0; i < docs; i++)
     {
         Document doc = new Document();
         if (Random().NextBoolean())
         {
             docStates[i] = 1;
             doc.Add(NewTextField("some", "value", Field.Store.YES));
         }
         doc.Add(NewTextField("all", "test", Field.Store.NO));
         doc.Add(NewTextField("id", "" + i, Field.Store.YES));
         writer.AddDocument(doc);
     }
     writer.Commit();
     int numDeletes = Random().Next(docs);
     for (int i = 0; i < numDeletes; i++)
     {
         int docID = Random().Next(docs);
         writer.DeleteDocuments(new Term("id", "" + docID));
         docStates[docID] = 2;
     }
     writer.Dispose();
     return docStates;
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:26,代码来源:TestFieldValueFilter.cs

示例3: BeforeClass

        public void BeforeClass()
        {
            Random random = Random();
            Directory = NewDirectory();
            Stopword = "" + RandomChar();
            CharacterRunAutomaton stopset = new CharacterRunAutomaton(BasicAutomata.MakeString(Stopword));
            Analyzer = new MockAnalyzer(random, MockTokenizer.WHITESPACE, false, stopset);
            RandomIndexWriter iw = new RandomIndexWriter(random, Directory, Analyzer);
            Document doc = new Document();
            Field id = new StringField("id", "", Field.Store.NO);
            Field field = new TextField("field", "", Field.Store.NO);
            doc.Add(id);
            doc.Add(field);

            // index some docs
            int numDocs = AtLeast(1000);
            for (int i = 0; i < numDocs; i++)
            {
                id.StringValue = Convert.ToString(i);
                field.StringValue = RandomFieldContents();
                iw.AddDocument(doc);
            }

            // delete some docs
            int numDeletes = numDocs / 20;
            for (int i = 0; i < numDeletes; i++)
            {
                Term toDelete = new Term("id", Convert.ToString(random.Next(numDocs)));
                if (random.NextBoolean())
                {
                    iw.DeleteDocuments(toDelete);
                }
                else
                {
                    iw.DeleteDocuments(new TermQuery(toDelete));
                }
            }

            Reader = iw.Reader;
            S1 = NewSearcher(Reader);
            S2 = NewSearcher(Reader);
            iw.Dispose();
        }
开发者ID:WakeflyCBass,项目名称:lucenenet,代码行数:43,代码来源:SearchEquivalenceTestBase.cs

示例4: TestRandom

        public virtual void TestRandom()
        {
            Directory d = NewDirectory();
            RandomIndexWriter w = new RandomIndexWriter(Random(), d);
            w.w.Config.SetMaxBufferedDocs(17);
            int numDocs = AtLeast(100);
            HashSet<string> aDocs = new HashSet<string>();
            for (int i = 0; i < numDocs; i++)
            {
                Document doc = new Document();
                string v;
                if (Random().Next(5) == 4)
                {
                    v = "a";
                    aDocs.Add("" + i);
                }
                else
                {
                    v = "b";
                }
                Field f = NewStringField("field", v, Field.Store.NO);
                doc.Add(f);
                doc.Add(NewStringField("id", "" + i, Field.Store.YES));
                w.AddDocument(doc);
            }

            int numDelDocs = AtLeast(10);
            for (int i = 0; i < numDelDocs; i++)
            {
                string delID = "" + Random().Next(numDocs);
                w.DeleteDocuments(new Term("id", delID));
                aDocs.Remove(delID);
            }

            IndexReader r = w.Reader;
            w.Dispose();
            TopDocs hits = NewSearcher(r).Search(new MatchAllDocsQuery(), new QueryWrapperFilter(new TermQuery(new Term("field", "a"))), numDocs);
            Assert.AreEqual(aDocs.Count, hits.TotalHits);
            foreach (ScoreDoc sd in hits.ScoreDocs)
            {
                Assert.IsTrue(aDocs.Contains(r.Document(sd.Doc).Get("id")));
            }
            r.Dispose();
            d.Dispose();
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:45,代码来源:TestQueryWrapperFilter.cs


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