first you submit your web site to

.
Then at regular periods special softwares called as bots and sometimes even as robots crawl the net lloking for new web spages and contents.
then it send the data to an indexing software where all the web pages are organised in terms of keywords,called as the database.then when someone searches on net,a query is automaticaaly generated which extracts the required information form the database.