public AssertingDocsEnum(DocsEnum @in, bool failOnUnsupportedDocID)
     : base(@in)
 {
     try
     {
         int docid = @in.DocID;
         Debug.Assert(docid == -1, @in.GetType() + ": invalid initial doc id: " + docid);
     }
     catch (System.NotSupportedException /*e*/)
     {
         if (failOnUnsupportedDocID)
         {
             throw; // LUCENENET: CA2200: Rethrow to preserve stack details (https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2200-rethrow-to-preserve-stack-details)
         }
     }
     doc = -1;
 }
示例#2
0
 public AssertingDocsEnum(DocsEnum @in, bool failOnUnsupportedDocID)
     : base(@in)
 {
     try
     {
         int docid = @in.DocID;
         Debug.Assert(docid == -1, @in.GetType() + ": invalid initial doc id: " + docid);
     }
     catch (System.NotSupportedException e)
     {
         if (failOnUnsupportedDocID)
         {
             throw e;
         }
     }
     Doc = -1;
 }
示例#3
0
        public virtual void TestRandomDocs()
        {
            Directory         dir    = NewDirectory();
            RandomIndexWriter writer = new RandomIndexWriter(Random, dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)).SetMergePolicy(NewLogMergePolicy()));
            int numDocs = AtLeast(49);
            int max     = 15678;
            int term    = Random.Next(max);

            int[]     freqInDoc  = new int[numDocs];
            FieldType customType = new FieldType(TextField.TYPE_NOT_STORED);

            customType.OmitNorms = true;
            for (int i = 0; i < numDocs; i++)
            {
                Document      doc     = new Document();
                StringBuilder builder = new StringBuilder();
                for (int j = 0; j < 199; j++)
                {
                    int nextInt = Random.Next(max);
                    builder.Append(nextInt).Append(' ');
                    if (nextInt == term)
                    {
                        freqInDoc[i]++;
                    }
                }
                doc.Add(NewField(FieldName, builder.ToString(), customType));
                writer.AddDocument(doc);
            }

            IndexReader reader = writer.GetReader();

            writer.Dispose();

            int num = AtLeast(13);

            for (int i = 0; i < num; i++)
            {
                BytesRef           bytes            = new BytesRef("" + term);
                IndexReaderContext topReaderContext = reader.Context;
                foreach (AtomicReaderContext context in topReaderContext.Leaves)
                {
                    int      maxDoc   = context.AtomicReader.MaxDoc;
                    DocsEnum docsEnum = TestUtil.Docs(Random, context.Reader, FieldName, bytes, null, null, DocsFlags.FREQS);
                    if (FindNext(freqInDoc, context.DocBase, context.DocBase + maxDoc) == int.MaxValue)
                    {
                        Assert.IsNull(docsEnum);
                        continue;
                    }
                    Assert.IsNotNull(docsEnum);
                    docsEnum.NextDoc();
                    for (int j = 0; j < maxDoc; j++)
                    {
                        if (freqInDoc[context.DocBase + j] != 0)
                        {
                            Assert.AreEqual(j, docsEnum.DocID);
                            Assert.AreEqual(docsEnum.Freq, freqInDoc[context.DocBase + j]);
                            if (i % 2 == 0 && Random.Next(10) == 0)
                            {
                                int next       = FindNext(freqInDoc, context.DocBase + j + 1, context.DocBase + maxDoc) - context.DocBase;
                                int advancedTo = docsEnum.Advance(next);
                                if (next >= maxDoc)
                                {
                                    Assert.AreEqual(DocIdSetIterator.NO_MORE_DOCS, advancedTo);
                                }
                                else
                                {
                                    Assert.IsTrue(next >= advancedTo, "advanced to: " + advancedTo + " but should be <= " + next);
                                }
                            }
                            else
                            {
                                docsEnum.NextDoc();
                            }
                        }
                    }
                    Assert.AreEqual(DocIdSetIterator.NO_MORE_DOCS, docsEnum.DocID, "DocBase: " + context.DocBase + " maxDoc: " + maxDoc + " " + docsEnum.GetType());
                }
            }

            reader.Dispose();
            dir.Dispose();
        }
示例#4
0
 public override int DocID()
 {
     Debug.Assert(Doc == base.DocID(), " invalid docID() in " + DocsEnum.GetType() + " " + base.DocID() + " instead of " + Doc);
     return(Doc);
 }
 public AssertingDocsEnum(DocsEnum @in, bool failOnUnsupportedDocID)
     : base(@in)
 {
     try
     {
         int docid = @in.DocID();
         Debug.Assert(docid == -1, @in.GetType() + ": invalid initial doc id: " + docid);
     }
     catch (System.NotSupportedException e)
     {
         if (failOnUnsupportedDocID)
         {
             throw e;
         }
     }
     Doc = -1;
 }
示例#6
0
 public AssertingDocsEnum(DocsEnum @in, bool failOnUnsupportedDocID)
     : base(@in)
 {
     try
     {
         int docid = @in.DocID;
         if (Debugging.AssertsEnabled)
         {
             Debugging.Assert(docid == -1, "{0}: invalid initial doc id: {1}", @in.GetType(), docid);
         }
     }
     catch (Exception e) when(e.IsUnsupportedOperationException())
     {
         if (failOnUnsupportedDocID)
         {
             throw; // LUCENENET: CA2200: Rethrow to preserve stack details (https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2200-rethrow-to-preserve-stack-details)
         }
     }
     doc = -1;
 }