TestMultiLevelSkipListpublic class TestMultiLevelSkipList extends TestCase This testcase tests whether multi-level skipping is being used
to reduce I/O while skipping through posting lists.
Skipping in general is already covered by several other
testcases. |
Fields Summary |
---|
private int | counter |
Methods Summary |
---|
public void | checkSkipTo(org.apache.lucene.index.TermPositions tp, int target, int maxCounter)
tp.skipTo(target);
if (maxCounter < counter) {
fail("Too many bytes read: " + counter);
}
assertEquals("Wrong document " + tp.doc() + " after skipTo target " + target, target, tp.doc());
assertEquals("Frequency is not 1: " + tp.freq(), 1,tp.freq());
tp.nextPosition();
byte[] b = new byte[1];
tp.getPayload(b, 0);
assertEquals("Wrong payload for the target " + target + ": " + b[0], (byte) target, b[0]);
| public void | testSimpleSkip()
RAMDirectory dir = new RAMDirectory();
IndexWriter writer = new IndexWriter(dir, new PayloadAnalyzer(), true);
Term term = new Term("test", "a");
for (int i = 0; i < 5000; i++) {
Document d1 = new Document();
d1.add(new Field(term.field(), term.text(), Store.NO, Index.TOKENIZED));
writer.addDocument(d1);
}
writer.flush();
writer.optimize();
writer.close();
IndexReader reader = IndexReader.open(dir);
SegmentTermPositions tp = (SegmentTermPositions) reader.termPositions(term);
tp.freqStream = new CountingStream(tp.freqStream);
tp.next();
checkSkipTo(tp, 14, 185); // no skips
checkSkipTo(tp, 17, 190); // one skip on level 0
checkSkipTo(tp, 287, 200); // one skip on level 1, two on level 0
// this test would fail if we had only one skip level,
// because than more bytes would be read from the freqStream
checkSkipTo(tp, 4800, 250);// one skip on level 2
|
|