In a nutshell
A search engine can't read the whole web each time you search, so it prepares in advance. A crawler starts at one page and follows links from page to page, discovering them all. It then builds an inverted index: a table mapping each word to the pages that contain it, so a query is answered by reading one row. The matching pages are ordered by relevance plus importance, where PageRank rates a page as important when many important pages link to it. The result is the ranked list you see.