Term term = terms.get(random().nextInt(num));
TopDocs queryResult = searcher.search(new TermQuery(term), reader.maxDoc());
MatchAllDocsQuery matchAll = new MatchAllDocsQuery();
final TermFilter filter = termFilter(term);
TopDocs filterResult = searcher.search(matchAll, filter, reader.maxDoc());
assertEquals(filterResult.totalHits, queryResult.totalHits);
ScoreDoc[] scoreDocs = filterResult.scoreDocs;
for (int j = 0; j < scoreDocs.length; j++) {
assertEquals(scoreDocs[j].doc, queryResult.scoreDocs[j].doc);
}