Wow, I doubt that anybody can tell you this with reply on forum. If you want to learn how search engine works, learn some basic programming.
Search engines have two major functions - crawling & building an index, and providing answers by calculating relevancy & serving results. For more information visit: http://www.seomoz.org/beginners-guide-to-seo/how-search-engines-operate
They basically have their own algorithms for ranking pages according to various keywords. In general, they give importance to relevant, high quality content.
Here is a vid on how Google works - http://www.youtube.com/watch?v=BNHR6IQJGZs Here is another one I like - http://www.youtube.com/watch?v=KyCYyoGusqs So, baisically, Google is a free keyword ranking tool, that indexes and ranks webpages for free. But, of course, with its paid search and tons of other services it's making money these days.
Have a look at this article - http://www.webconfs.com/seo-tutorial/introduction-to-seo.php#1. How Search Engines Work|outline This helps you utmost.
As I know, spiders start their journeys with a list of page URLs that have previously been added to their index (database). As it visits these pages, crawling the code and copy, it adds new pages (links) that it finds on the page to its index. As such, one could refer to a spider as feeding an evolving index, which is discussed below
You'll have to go through all of the informative websites about how search engine works for you to know that. You'll really have to study SEO for you to understand how it search engine works. But if ever there's a part of it, a specific part or branch of SEO, that you don't understand, do ask us here and I think that way we can help you understand it. But not with this broad question.