Check this out :

http://www.geeksforgeeks.org/search-engines-work/