evil up RIW

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1152784 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2011-08-01 14:08:29 +00:00
parent ed828e46ff
commit 7e21a0c843
1 changed files with 16 additions and 2 deletions

View File

@ -29,6 +29,7 @@ import org.apache.lucene.document.Document;
import org.apache.lucene.index.IndexWriter; // javadoc
import org.apache.lucene.index.codecs.CodecProvider;
import org.apache.lucene.index.values.ValueType;
import org.apache.lucene.search.Query;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.LuceneTestCase;
@ -299,6 +300,10 @@ public class RandomIndexWriter implements Closeable {
w.deleteDocuments(term);
}
public void deleteDocuments(Query q) throws CorruptIndexException, IOException {
w.deleteDocuments(q);
}
public void commit() throws CorruptIndexException, IOException {
w.commit();
switchDoDocValues();
@ -321,11 +326,16 @@ public class RandomIndexWriter implements Closeable {
}
private boolean doRandomOptimize = true;
private boolean doRandomOptimizeAssert = true;
public void setDoRandomOptimize(boolean v) {
doRandomOptimize = v;
}
public void setDoRandomOptimizeAssert(boolean v) {
doRandomOptimizeAssert = v;
}
private void doRandomOptimize() throws IOException {
if (doRandomOptimize) {
final int segCount = w.getSegmentCount();
@ -336,7 +346,7 @@ public class RandomIndexWriter implements Closeable {
// partial optimize
final int limit = _TestUtil.nextInt(r, 1, segCount);
w.optimize(limit);
assert w.getSegmentCount() <= limit: "limit=" + limit + " actual=" + w.getSegmentCount();
assert !doRandomOptimizeAssert || w.getSegmentCount() <= limit: "limit=" + limit + " actual=" + w.getSegmentCount();
}
}
switchDoDocValues();
@ -364,7 +374,11 @@ public class RandomIndexWriter implements Closeable {
}
w.commit();
switchDoDocValues();
if (r.nextBoolean()) {
return IndexReader.open(w.getDirectory(), new KeepOnlyLastCommitDeletionPolicy(), r.nextBoolean(), _TestUtil.nextInt(r, 1, 10), w.getConfig().getCodecProvider());
} else {
return w.getReader(applyDeletions);
}
}
}