LUCENE-3268: make TestScoredDocIDsUtils more robust to document deletions

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1142676 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shai Erera 2011-07-04 14:06:38 +00:00
parent ae27b645a4
commit d04561c703
1 changed files with 10 additions and 14 deletions

View File

@ -126,23 +126,18 @@ public class TestScoredDocIDsUtils extends LuceneTestCase {
Directory dir = newDirectory();
IndexReader reader = createReaderWithNDocs(random, N_DOCS, docFactory, dir);
try {
int numErasedDocs = reader.numDeletedDocs();
ScoredDocIDs allDocs = ScoredDocIdsUtils.createAllDocsScoredDocIDs(reader);
ScoredDocIDsIterator it = allDocs.iterator();
int numIteratedDocs = 0;
while (it.next()) {
numIteratedDocs++;
int docNum = it.getDocID();
assertFalse(
"Deleted docs must not appear in the allDocsScoredDocIds set: " + docNum,
docFactory.markedDeleted(docNum));
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);
assertEquals("Wrong number of (live) documents", N_DOCS
- numErasedDocs, numIteratedDocs);
// Get all 'alpha' documents
ScoredDocIdCollector collector = ScoredDocIdCollector.create(reader.maxDoc(), false);
@ -169,9 +164,9 @@ public class TestScoredDocIDsUtils extends LuceneTestCase {
assertFalse(
"Complement-Set must not contain deleted documents (doc="+docNum+")",
deleted != null && deleted.get(docNum));
assertFalse(
"Complement-Set must not contain deleted documents (doc="+docNum+")",
docFactory.markedDeleted(docNum));
assertNull(
"Complement-Set must not contain docs from the original set (doc="+ docNum+")",
reader.document(docNum).getFieldable("del"));
assertFalse(
"Complement-Set must not contain docs from the original set (doc="+docNum+")",
resultSet.fastGet(docNum));
@ -211,6 +206,9 @@ public class TestScoredDocIDsUtils extends LuceneTestCase {
Document doc = new Document();
if (markedDeleted(docNum)) {
doc.add(deletionMark);
// Add a special field for docs that are marked for deletion. Later we
// assert that those docs are not returned by all-scored-doc-IDs.
doc.add(new Field("del", Integer.toString(docNum), Store.YES, Index.NO));
}
if (haveAlpha(docNum)) {
@ -225,11 +223,9 @@ public class TestScoredDocIDsUtils extends LuceneTestCase {
}
static IndexReader createReaderWithNDocs(Random random, int nDocs, DocumentFactory docFactory, Directory dir) throws IOException {
// Create the index - force log-merge policy since we rely on docs order.
RandomIndexWriter writer = new RandomIndexWriter(random, dir,
newIndexWriterConfig(random, TEST_VERSION_CURRENT,
new MockAnalyzer(random, MockTokenizer.KEYWORD, false))
.setMergePolicy(newLogMergePolicy()));
new MockAnalyzer(random, MockTokenizer.KEYWORD, false)));
for (int docNum = 0; docNum < nDocs; docNum++) {
writer.addDocument(docFactory.getDoc(docNum));
}