Search engines have two major functions – crawling & building an index, and providing answers by calculating relevancy & serving results.
It is the process where “web crawlers/Googlebot/spider” are used to find out publicly available new and updated webpages and report back to Google.
It is like organizing billions of books with no central filing system. Or you can say that, During the crawl process Google gathers the webpages, and then creates an index based on the information about words and their locations.
How Search Works, A Video by Matt Cutts
Search. It happens billions of times a day in the blink of an eye. Explore the art and science that makes it possible.
The life span of a Google query is less then 1/2 second, and involves quite a few steps before you see the most relevant results. Here’s how it all works. If you want more details on how search engines work, you can read about them in Google Inside Search