public void testTfPruning() throws Exception {
RAMDirectory targetDir = new RAMDirectory();
IndexReader in = IndexReader.open(sourceDir, true);
TFTermPruningPolicy tfp = new TFTermPruningPolicy(in, null, null, 2);
PruningReader tfr = new PruningReader(in, null, tfp);
// verify
assertTD(tfr, new Term("body", "one"), new int[]{1, 2, 3, 4});
assertTD(tfr, new Term("body", "two"), new int[]{1, 2});
assertTD(tfr, new Term("body", "three"), new int[]{1, 3});
assertTD(tfr, new Term("test", "one"), new int[]{4});
assertTDCount(tfr, new Term("body", "four"), 0);
assertTDCount(tfr, new Term("test", "four"), 0);
// verify new reader
WhitespaceAnalyzer analyzer = new WhitespaceAnalyzer(TEST_VERSION_CURRENT);
IndexWriter iw = new IndexWriter(targetDir, new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer));
iw.addIndexes(new IndexReader[]{tfr});
iw.close();
IndexReader ir = IndexReader.open(targetDir, true);
assertTD(ir, new Term("body", "one"), new int[]{1, 2, 3, 4});
assertTD(ir, new Term("body", "two"), new int[]{1, 2});
assertTD(ir, new Term("body", "three"), new int[]{1, 3});
assertTD(ir, new Term("test", "one"), new int[]{4});
tfr.close();
ir.close();
}