public void TestIsCacheable() { Directory dir = new RAMDirectory(); IndexWriter writer = new IndexWriter(dir, new KeywordAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED); writer.Close(); IndexReader reader = IndexReader.Open(dir, true); // not cacheable: assertDocIdSetCacheable(reader, new QueryWrapperFilter(new TermQuery(new Term("test", "value"))), false); // returns default empty docidset, always cacheable: assertDocIdSetCacheable(reader, NumericRangeFilter.NewIntRange("test", 10000, -10000, true, true), true); // is cacheable: assertDocIdSetCacheable(reader, FieldCacheRangeFilter.NewIntRange("test", 10, 20, true, true), true); // a openbitset filter is always cacheable assertDocIdSetCacheable(reader, new AnonymousFilter3(), true); reader.Close(); }
public virtual void TestIsCacheAble() { Directory dir = NewDirectory(); RandomIndexWriter writer = new RandomIndexWriter(Random(), dir, Similarity, TimeZone); writer.AddDocument(new Document()); writer.Dispose(); IndexReader reader = SlowCompositeReaderWrapper.Wrap(DirectoryReader.Open(dir)); // not cacheable: AssertDocIdSetCacheable(reader, new QueryWrapperFilter(new TermQuery(new Term("test", "value"))), false); // returns default empty docidset, always cacheable: AssertDocIdSetCacheable(reader, NumericRangeFilter.NewIntRange("test", Convert.ToInt32(10000), Convert.ToInt32(-10000), true, true), true); // is cacheable: AssertDocIdSetCacheable(reader, FieldCacheRangeFilter.NewIntRange("test", Convert.ToInt32(10), Convert.ToInt32(20), true, true), true); // a fixedbitset filter is always cacheable AssertDocIdSetCacheable(reader, new FilterAnonymousInnerClassHelper3(this), true); reader.Dispose(); dir.Dispose(); }
public virtual void TestFieldCacheRangeFilterInts() { IndexReader reader = IndexReader.Open((Directory)signedIndex.index, true, null); IndexSearcher Search = new IndexSearcher(reader); int numDocs = reader.NumDocs(); int medId = ((maxId - minId) / 2); System.Int32 minIdO = (System.Int32)minId; System.Int32 maxIdO = (System.Int32)maxId; System.Int32 medIdO = (System.Int32)medId; Assert.AreEqual(numDocs, 1 + maxId - minId, "num of docs"); ScoreDoc[] result; Query q = new TermQuery(new Term("body", "body")); // test id, bounded on both ends result = Search.Search(q, FieldCacheRangeFilter.NewIntRange("id", minIdO, maxIdO, T, T), numDocs, null).ScoreDocs; Assert.AreEqual(numDocs, result.Length, "find all"); result = Search.Search(q, FieldCacheRangeFilter.NewIntRange("id", minIdO, maxIdO, T, F), numDocs, null).ScoreDocs; Assert.AreEqual(numDocs - 1, result.Length, "all but last"); result = Search.Search(q, FieldCacheRangeFilter.NewIntRange("id", minIdO, maxIdO, F, T), numDocs, null).ScoreDocs; Assert.AreEqual(numDocs - 1, result.Length, "all but first"); result = Search.Search(q, FieldCacheRangeFilter.NewIntRange("id", minIdO, maxIdO, F, F), numDocs, null).ScoreDocs; Assert.AreEqual(numDocs - 2, result.Length, "all but ends"); result = Search.Search(q, FieldCacheRangeFilter.NewIntRange("id", medIdO, maxIdO, T, T), numDocs, null).ScoreDocs; Assert.AreEqual(1 + maxId - medId, result.Length, "med and up"); result = Search.Search(q, FieldCacheRangeFilter.NewIntRange("id", minIdO, medIdO, T, T), numDocs, null).ScoreDocs; Assert.AreEqual(1 + medId - minId, result.Length, "up to med"); // unbounded id result = Search.Search(q, FieldCacheRangeFilter.NewIntRange("id", null, null, T, T), numDocs, null).ScoreDocs; Assert.AreEqual(numDocs, result.Length, "find all"); result = Search.Search(q, FieldCacheRangeFilter.NewIntRange("id", minIdO, null, T, F), numDocs, null).ScoreDocs; Assert.AreEqual(numDocs, result.Length, "min and up"); result = Search.Search(q, FieldCacheRangeFilter.NewIntRange("id", null, maxIdO, F, T), numDocs, null).ScoreDocs; Assert.AreEqual(numDocs, result.Length, "max and down"); result = Search.Search(q, FieldCacheRangeFilter.NewIntRange("id", minIdO, null, F, F), numDocs, null).ScoreDocs; Assert.AreEqual(numDocs - 1, result.Length, "not min, but up"); result = Search.Search(q, FieldCacheRangeFilter.NewIntRange("id", null, maxIdO, F, F), numDocs, null).ScoreDocs; Assert.AreEqual(numDocs - 1, result.Length, "not max, but down"); result = Search.Search(q, FieldCacheRangeFilter.NewIntRange("id", medIdO, maxIdO, T, F), numDocs, null).ScoreDocs; Assert.AreEqual(maxId - medId, result.Length, "med and up, not max"); result = Search.Search(q, FieldCacheRangeFilter.NewIntRange("id", minIdO, medIdO, F, T), numDocs, null).ScoreDocs; Assert.AreEqual(medId - minId, result.Length, "not min, up to med"); // very small sets result = Search.Search(q, FieldCacheRangeFilter.NewIntRange("id", minIdO, minIdO, F, F), numDocs, null).ScoreDocs; Assert.AreEqual(0, result.Length, "min,min,F,F"); result = Search.Search(q, FieldCacheRangeFilter.NewIntRange("id", medIdO, medIdO, F, F), numDocs, null).ScoreDocs; Assert.AreEqual(0, result.Length, "med,med,F,F"); result = Search.Search(q, FieldCacheRangeFilter.NewIntRange("id", maxIdO, maxIdO, F, F), numDocs, null).ScoreDocs; Assert.AreEqual(0, result.Length, "max,max,F,F"); result = Search.Search(q, FieldCacheRangeFilter.NewIntRange("id", minIdO, minIdO, T, T), numDocs, null).ScoreDocs; Assert.AreEqual(1, result.Length, "min,min,T,T"); result = Search.Search(q, FieldCacheRangeFilter.NewIntRange("id", null, minIdO, F, T), numDocs, null).ScoreDocs; Assert.AreEqual(1, result.Length, "nul,min,F,T"); result = Search.Search(q, FieldCacheRangeFilter.NewIntRange("id", maxIdO, maxIdO, T, T), numDocs, null).ScoreDocs; Assert.AreEqual(1, result.Length, "max,max,T,T"); result = Search.Search(q, FieldCacheRangeFilter.NewIntRange("id", maxIdO, null, T, F), numDocs, null).ScoreDocs; Assert.AreEqual(1, result.Length, "max,nul,T,T"); result = Search.Search(q, FieldCacheRangeFilter.NewIntRange("id", medIdO, medIdO, T, T), numDocs, null).ScoreDocs; Assert.AreEqual(1, result.Length, "med,med,T,T"); // special cases System.Int32 tempAux = (System.Int32)System.Int32.MaxValue; result = Search.Search(q, FieldCacheRangeFilter.NewIntRange("id", tempAux, null, F, F), numDocs, null).ScoreDocs; Assert.AreEqual(0, result.Length, "overflow special case"); System.Int32 tempAux2 = (System.Int32)System.Int32.MinValue; result = Search.Search(q, FieldCacheRangeFilter.NewIntRange("id", null, tempAux2, F, F), numDocs, null).ScoreDocs; Assert.AreEqual(0, result.Length, "overflow special case"); result = Search.Search(q, FieldCacheRangeFilter.NewIntRange("id", maxIdO, minIdO, T, T), numDocs, null).ScoreDocs; Assert.AreEqual(0, result.Length, "inverse range"); }
public virtual void TestFieldCacheRangeFilterInts() { IndexReader reader = SignedIndexReader; IndexSearcher search = NewSearcher(reader); int numDocs = reader.NumDocs; int medId = ((MaxId - MinId) / 2); int?minIdO = Convert.ToInt32(MinId); int?maxIdO = Convert.ToInt32(MaxId); int?medIdO = Convert.ToInt32(medId); Assert.AreEqual(numDocs, 1 + MaxId - MinId, "num of docs"); ScoreDoc[] result; Query q = new TermQuery(new Term("body", "body")); // test id, bounded on both ends result = search.Search(q, FieldCacheRangeFilter.NewIntRange("id", minIdO, maxIdO, T, T), numDocs).ScoreDocs; Assert.AreEqual(numDocs, result.Length, "find all"); result = search.Search(q, FieldCacheRangeFilter.NewIntRange("id", minIdO, maxIdO, T, F), numDocs).ScoreDocs; Assert.AreEqual(numDocs - 1, result.Length, "all but last"); result = search.Search(q, FieldCacheRangeFilter.NewIntRange("id", minIdO, maxIdO, F, T), numDocs).ScoreDocs; Assert.AreEqual(numDocs - 1, result.Length, "all but first"); result = search.Search(q, FieldCacheRangeFilter.NewIntRange("id", minIdO, maxIdO, F, F), numDocs).ScoreDocs; Assert.AreEqual(numDocs - 2, result.Length, "all but ends"); result = search.Search(q, FieldCacheRangeFilter.NewIntRange("id", medIdO, maxIdO, T, T), numDocs).ScoreDocs; Assert.AreEqual(1 + MaxId - medId, result.Length, "med and up"); result = search.Search(q, FieldCacheRangeFilter.NewIntRange("id", minIdO, medIdO, T, T), numDocs).ScoreDocs; Assert.AreEqual(1 + medId - MinId, result.Length, "up to med"); // unbounded id result = search.Search(q, FieldCacheRangeFilter.NewIntRange("id", null, null, T, T), numDocs).ScoreDocs; Assert.AreEqual(numDocs, result.Length, "find all"); result = search.Search(q, FieldCacheRangeFilter.NewIntRange("id", minIdO, null, T, F), numDocs).ScoreDocs; Assert.AreEqual(numDocs, result.Length, "min and up"); result = search.Search(q, FieldCacheRangeFilter.NewIntRange("id", null, maxIdO, F, T), numDocs).ScoreDocs; Assert.AreEqual(numDocs, result.Length, "max and down"); result = search.Search(q, FieldCacheRangeFilter.NewIntRange("id", minIdO, null, F, F), numDocs).ScoreDocs; Assert.AreEqual(numDocs - 1, result.Length, "not min, but up"); result = search.Search(q, FieldCacheRangeFilter.NewIntRange("id", null, maxIdO, F, F), numDocs).ScoreDocs; Assert.AreEqual(numDocs - 1, result.Length, "not max, but down"); result = search.Search(q, FieldCacheRangeFilter.NewIntRange("id", medIdO, maxIdO, T, F), numDocs).ScoreDocs; Assert.AreEqual(MaxId - medId, result.Length, "med and up, not max"); result = search.Search(q, FieldCacheRangeFilter.NewIntRange("id", minIdO, medIdO, F, T), numDocs).ScoreDocs; Assert.AreEqual(medId - MinId, result.Length, "not min, up to med"); // very small sets result = search.Search(q, FieldCacheRangeFilter.NewIntRange("id", minIdO, minIdO, F, F), numDocs).ScoreDocs; Assert.AreEqual(0, result.Length, "min,min,F,F"); result = search.Search(q, FieldCacheRangeFilter.NewIntRange("id", medIdO, medIdO, F, F), numDocs).ScoreDocs; Assert.AreEqual(0, result.Length, "med,med,F,F"); result = search.Search(q, FieldCacheRangeFilter.NewIntRange("id", maxIdO, maxIdO, F, F), numDocs).ScoreDocs; Assert.AreEqual(0, result.Length, "max,max,F,F"); result = search.Search(q, FieldCacheRangeFilter.NewIntRange("id", minIdO, minIdO, T, T), numDocs).ScoreDocs; Assert.AreEqual(1, result.Length, "min,min,T,T"); result = search.Search(q, FieldCacheRangeFilter.NewIntRange("id", null, minIdO, F, T), numDocs).ScoreDocs; Assert.AreEqual(1, result.Length, "nul,min,F,T"); result = search.Search(q, FieldCacheRangeFilter.NewIntRange("id", maxIdO, maxIdO, T, T), numDocs).ScoreDocs; Assert.AreEqual(1, result.Length, "max,max,T,T"); result = search.Search(q, FieldCacheRangeFilter.NewIntRange("id", maxIdO, null, T, F), numDocs).ScoreDocs; Assert.AreEqual(1, result.Length, "max,nul,T,T"); result = search.Search(q, FieldCacheRangeFilter.NewIntRange("id", medIdO, medIdO, T, T), numDocs).ScoreDocs; Assert.AreEqual(1, result.Length, "med,med,T,T"); // special cases result = search.Search(q, FieldCacheRangeFilter.NewIntRange("id", Convert.ToInt32(int.MaxValue), null, F, F), numDocs).ScoreDocs; Assert.AreEqual(0, result.Length, "overflow special case"); result = search.Search(q, FieldCacheRangeFilter.NewIntRange("id", null, Convert.ToInt32(int.MinValue), F, F), numDocs).ScoreDocs; Assert.AreEqual(0, result.Length, "overflow special case"); result = search.Search(q, FieldCacheRangeFilter.NewIntRange("id", maxIdO, minIdO, T, T), numDocs).ScoreDocs; Assert.AreEqual(0, result.Length, "inverse range"); }