This tutorial explain, How to implement pagination using query builder query in search. How to use p.offset, p.limit and p.guessTotal. How to search without iterating whole results at once.
AEM Query console : http://localhost:4502/libs/cq/search/content/querydebug.html