Fix how matches are found in search

Instead of keeping track of where the search starts, just
keep track of the number of pages and make sure we don't
visit pages more than once.