public virtual void TestNullDocIdSet() { // Tests that if a Filter produces a null DocIdSet, which is given to // IndexSearcher, everything works fine. This came up in LUCENE-1754. Directory dir = new RAMDirectory(); IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), MaxFieldLength.UNLIMITED, null); Document doc = new Document(); doc.Add(new Field("c", "val", Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS)); writer.AddDocument(doc, null); writer.Close(); // First verify the document is searchable. IndexSearcher searcher = new IndexSearcher(dir, true, null); Assert.AreEqual(1, searcher.Search(new MatchAllDocsQuery(), 10, null).TotalHits); // Now search w/ a Filter which returns a null DocIdSet Filter f = new AnonymousClassFilter(this); Assert.AreEqual(0, searcher.Search(new MatchAllDocsQuery(), f, 10, null).TotalHits); searcher.Close(); }
public virtual void TestTopDocsScores() { // There was previously a bug in FieldSortedHitQueue.maxscore when only a single // doc was added. That is what the following tests for. Sort sort = new Sort(); int nDocs = 10; // try to pick a query that will result in an unnormalized // score greater than 1 to test for correct normalization TopDocs docs1 = full.Search(queryE, null, nDocs, sort); // a filter that only allows through the first hit Filter filt = new AnonymousClassFilter(docs1, this); TopDocs docs2 = full.Search(queryE, filt, nDocs, sort); Assert.AreEqual(docs1.ScoreDocs[0].Score, docs2.ScoreDocs[0].Score, 1e-6); }
public virtual void TestNullDocIdSet() { // Tests that if a Filter produces a null DocIdSet, which is given to // IndexSearcher, everything works fine. This came up in LUCENE-1754. Directory dir = new RAMDirectory(); IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), MaxFieldLength.UNLIMITED); Document doc = new Document(); doc.Add(new Field("c", "val", Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS)); writer.AddDocument(doc); writer.Close(); // First verify the document is searchable. IndexSearcher searcher = new IndexSearcher(dir, true); Assert.AreEqual(1, searcher.Search(new MatchAllDocsQuery(), 10).TotalHits); // Now search w/ a Filter which returns a null DocIdSet Filter f = new AnonymousClassFilter(this); Assert.AreEqual(0, searcher.Search(new MatchAllDocsQuery(), f, 10).TotalHits); searcher.Close(); }