RAMDirectory dir = new RAMDirectory();
IndexWriter iw = new IndexWriter(dir, new StandardAnalyzer(), true);
addDoc("one", iw);
addDoc("two", iw);
addDoc("three four", iw);
iw.close();
IndexSearcher is = new IndexSearcher(dir);
Hits hits = is.search(new MatchAllDocsQuery());
assertEquals(3, hits.length());
// some artificial queries to trigger the use of skipTo():
BooleanQuery bq = new BooleanQuery();
bq.add(new MatchAllDocsQuery(), BooleanClause.Occur.MUST);
bq.add(new MatchAllDocsQuery(), BooleanClause.Occur.MUST);
hits = is.search(bq);
assertEquals(3, hits.length());
bq = new BooleanQuery();
bq.add(new MatchAllDocsQuery(), BooleanClause.Occur.MUST);
bq.add(new TermQuery(new Term("key", "three")), BooleanClause.Occur.MUST);
hits = is.search(bq);
assertEquals(1, hits.length());
// delete a document:
is.getIndexReader().delete(0);
hits = is.search(new MatchAllDocsQuery());
assertEquals(2, hits.length());
is.close();