Reworked pagination for better performance (at least in Lucene queries)