This is how a Google search works.
A Google software engineer head details in a video how the search engine scours the web on a daily basis, starting with the crawling and analysis of a site, crawling timelines, frequencies, priorities, indexing and filtering processes within the databases...
Want more? Ask any question in Google's Webmaster Help Forum.
