};
Directory dir = newDirectory();
IndexReader reader = createReaderWithNDocs(random, N_DOCS, docFactory, dir);
try {
ScoredDocIDs allDocs = ScoredDocIdsUtils.createAllDocsScoredDocIDs(reader);
ScoredDocIDsIterator it = allDocs.iterator();
int numIteratedDocs = 0;
while (it.next()) {
numIteratedDocs++;
int docNum = it.getDocID();
assertNull(
"Deleted docs must not appear in the allDocsScoredDocIds set: " + docNum,
reader.document(docNum).getFieldable("del"));
}
assertEquals("Wrong number of (live) documents", allDocs.size(), numIteratedDocs);
// Get all 'alpha' documents
ScoredDocIdCollector collector = ScoredDocIdCollector.create(reader.maxDoc(), false);
Query q = new TermQuery(new Term(DocumentFactory.field, DocumentFactory.alphaTxt));
IndexSearcher searcher = newSearcher(reader);
searcher.search(q, collector);
searcher.close();
ScoredDocIDs scoredDocIds = collector.getScoredDocIDs();
OpenBitSet resultSet = new OpenBitSetDISI(scoredDocIds.getDocIDs().iterator(), reader.maxDoc());
// Getting the complement set of the query result
ScoredDocIDs complementSet = ScoredDocIdsUtils.getComplementSet(scoredDocIds, reader);
assertEquals("Number of documents in complement set mismatch",
reader.numDocs() - scoredDocIds.size(), complementSet.size());
// now make sure the documents in the complement set are not deleted
// and not in the original result set
ScoredDocIDsIterator compIterator = complementSet.iterator();
while (compIterator.next()) {
int docNum = compIterator.getDocID();
assertFalse(
"Complement-Set must not contain deleted documents (doc="+docNum+")",
reader.isDeleted(docNum));