public virtual void TestDocsWithField() { FieldCache cache = FieldCache_Fields.DEFAULT; cache.PurgeAllCaches(); Assert.AreEqual(0, cache.CacheEntries.Length); cache.GetDoubles(Reader, "theDouble", true); // The double[] takes two slots (one w/ null parser, one // w/ real parser), and docsWithField should also // have been populated: Assert.AreEqual(3, cache.CacheEntries.Length); Bits bits = cache.GetDocsWithField(Reader, "theDouble"); // No new entries should appear: Assert.AreEqual(3, cache.CacheEntries.Length); Assert.IsTrue(bits is Bits_MatchAllBits); Ints ints = cache.GetInts(Reader, "sparse", true); Assert.AreEqual(6, cache.CacheEntries.Length); Bits docsWithField = cache.GetDocsWithField(Reader, "sparse"); Assert.AreEqual(6, cache.CacheEntries.Length); for (int i = 0; i < docsWithField.Length(); i++) { if (i % 2 == 0) { Assert.IsTrue(docsWithField.Get(i)); Assert.AreEqual(i, ints.Get(i)); } else { Assert.IsFalse(docsWithField.Get(i)); } } Ints numInts = cache.GetInts(Reader, "numInt", Random().NextBoolean()); docsWithField = cache.GetDocsWithField(Reader, "numInt"); for (int i = 0; i < docsWithField.Length(); i++) { if (i % 2 == 0) { Assert.IsTrue(docsWithField.Get(i)); Assert.AreEqual(i, numInts.Get(i)); } else { Assert.IsFalse(docsWithField.Get(i)); } } }
public virtual void TestNonIndexedFields() { Directory dir = NewDirectory(); RandomIndexWriter iw = new RandomIndexWriter(Random(), dir); Document doc = new Document(); doc.Add(new StoredField("bogusbytes", "bogus")); doc.Add(new StoredField("bogusshorts", "bogus")); doc.Add(new StoredField("bogusints", "bogus")); doc.Add(new StoredField("boguslongs", "bogus")); doc.Add(new StoredField("bogusfloats", "bogus")); doc.Add(new StoredField("bogusdoubles", "bogus")); doc.Add(new StoredField("bogusterms", "bogus")); doc.Add(new StoredField("bogustermsindex", "bogus")); doc.Add(new StoredField("bogusmultivalued", "bogus")); doc.Add(new StoredField("bogusbits", "bogus")); iw.AddDocument(doc); DirectoryReader ir = iw.Reader; iw.Dispose(); AtomicReader ar = GetOnlySegmentReader(ir); FieldCache cache = FieldCache_Fields.DEFAULT; cache.PurgeAllCaches(); Assert.AreEqual(0, cache.CacheEntries.Length); Bytes bytes = cache.GetBytes(ar, "bogusbytes", true); Assert.AreEqual(0, bytes.Get(0)); Shorts shorts = cache.GetShorts(ar, "bogusshorts", true); Assert.AreEqual(0, shorts.Get(0)); Ints ints = cache.GetInts(ar, "bogusints", true); Assert.AreEqual(0, ints.Get(0)); Longs longs = cache.GetLongs(ar, "boguslongs", true); Assert.AreEqual(0, longs.Get(0)); Floats floats = cache.GetFloats(ar, "bogusfloats", true); Assert.AreEqual(0, floats.Get(0), 0.0f); Doubles doubles = cache.GetDoubles(ar, "bogusdoubles", true); Assert.AreEqual(0, doubles.Get(0), 0.0D); BytesRef scratch = new BytesRef(); BinaryDocValues binaries = cache.GetTerms(ar, "bogusterms", true); binaries.Get(0, scratch); Assert.AreEqual(0, scratch.Length); SortedDocValues sorted = cache.GetTermsIndex(ar, "bogustermsindex"); Assert.AreEqual(-1, sorted.GetOrd(0)); sorted.Get(0, scratch); Assert.AreEqual(0, scratch.Length); SortedSetDocValues sortedSet = cache.GetDocTermOrds(ar, "bogusmultivalued"); sortedSet.Document = 0; Assert.AreEqual(SortedSetDocValues.NO_MORE_ORDS, sortedSet.NextOrd()); Bits bits = cache.GetDocsWithField(ar, "bogusbits"); Assert.IsFalse(bits.Get(0)); // check that we cached nothing Assert.AreEqual(0, cache.CacheEntries.Length); ir.Dispose(); dir.Dispose(); }
/// <summary> Forcible purges all cache entries from the FieldCache. /// <p/> /// This method will be called by tearDown to clean up FieldCache.DEFAULT. /// If a (poorly written) test has some expectation that the FieldCache /// will persist across test methods (ie: a static IndexReader) this /// method can be overridden to do nothing. /// <p/> /// </summary> /// <seealso cref="FieldCache.PurgeAllCaches()"> /// </seealso> protected internal virtual void PurgeFieldCache(FieldCache fc) { fc.PurgeAllCaches(); }