Ejemplo n.º 1
0
        public virtual void TestMostlySet()
        {
            Directory d       = NewDirectory();
            int       numBits = TestUtil.NextInt(Random(), 30, 1000);

            for (int numClear = 0; numClear < 20; numClear++)
            {
                BitVector bv = new BitVector(numBits);
                bv.InvertAll();
                int count = 0;
                while (count < numClear)
                {
                    int bit = Random().Next(numBits);
                    // Don't use getAndClear, so that count is recomputed
                    if (bv.Get(bit))
                    {
                        bv.Clear(bit);
                        count++;
                        Assert.AreEqual(numBits - count, bv.Count());
                    }
                }
            }

            d.Dispose();
        }
Ejemplo n.º 2
0
        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.NextInt32(Random, 50, 1000)));
            Document doc = new Document();
            Field field = NewStringField(fieldName, "", Field.Store.NO);
            doc.Add(field);
            List<string> terms = new List<string>();
            int num = AtLeast(200);
            for (int i = 0; i < num; i++)
            {
                string s = TestUtil.RandomUnicodeString(Random);
                field.SetStringValue(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));
                }
            }

            reader = writer.GetReader();
            searcher1 = NewSearcher(reader);
            searcher2 = NewSearcher(reader);
            writer.Dispose();
        }
Ejemplo n.º 3
0
 public override void Dispose()
 {
     IsOpen = false;
     if (CheckIndexOnClose_Renamed && DirectoryReader.IndexExists(this))
     {
         TestUtil.CheckIndex(this, CrossCheckTermVectorsOnClose_Renamed);
     }
     base.Dispose();
 }
 public virtual void TestAttributeReflection()
 {
     CharTermAttribute t = new CharTermAttribute();
     t.Append("foobar");
     TestUtil.AssertAttributeReflection(t, new Dictionary<string, object>()
     {
             { typeof(ICharTermAttribute).Name + "#term", "foobar" },
             { typeof(ITermToBytesRefAttribute).Name + "#bytes", new BytesRef("foobar") }
     });
 }
Ejemplo n.º 5
0
        public virtual void TestClearedBitNearEnd()
        {
            Directory d       = NewDirectory();
            int       numBits = TestUtil.NextInt(Random(), 7, 1000);
            BitVector bv      = new BitVector(numBits);

            bv.InvertAll();
            bv.Clear(numBits - TestUtil.NextInt(Random(), 1, 7));
            bv.Write(d, "test", NewIOContext(Random()));
            Assert.AreEqual(numBits - 1, bv.Count());
            d.Dispose();
        }
Ejemplo n.º 6
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         isOpen = false;
         if (checkIndexOnClose && DirectoryReader.IndexExists(this))
         {
             TestUtil.CheckIndex(this, crossCheckTermVectorsOnClose);
         }
         base.Dispose(disposing);
     }
 }
Ejemplo n.º 7
0
        public virtual void TestLazySkipping()
        {
            string fieldFormat = TestUtil.GetPostingsFormat(this.Field);

            AssumeFalse("this test cannot run with Memory postings format", fieldFormat.Equals("Memory"));
            AssumeFalse("this test cannot run with Direct postings format", fieldFormat.Equals("Direct"));
            AssumeFalse("this test cannot run with SimpleText postings format", fieldFormat.Equals("SimpleText"));

            // test whether only the minimum amount of seeks()
            // are performed
            PerformTest(5);
            PerformTest(10);
        }
Ejemplo n.º 8
0
 protected override bool CodecAcceptsHugeBinaryValues(string field)
 {
     return(TestUtil.FieldSupportsHugeBinaryDocValues(field));
 }