The search engines look at various factors to rank the relevance of a web page. While they use these factors differently, here are the common factors they look at:

Age = both Google and Yahoo (to a lesser extent) do not give top ranking new sites immediately. There is this thing called "sandboxing" whereby new sites, especially those who are running a very aggressive linking strategy, find themselves not showing in the SEs for even up to 6 months. SEs seem to believe that there is a natural growth for websites, and any site that grows beyond their predefined pattern gets sandboxed.

Content = the more relevant your content to the search term, you can expect better rankings for that search term (considering other factors of course)

Keyword density = the main keywords of the page as well as special formatting used (if keywords are in bold, H1 or other formatting)

How it fares in the results = when a user clicks on the site in the search results, does the user stay (if so, then it must be relevant to the search) or does the user leave immediately (which means they haven’t found what they are looking for)

Site structure = where the content appears in your HTML code (the higher the better)

Backlinks = quality of backlinks, not quantity. Who is linking to you? Who you link to is also very important. If your site talks of website marketing and you are linking to mortgage financing, then that can negatively send a signal to SEs

I suggest you check out the following resources to learn more

Search Engine Watch http://searchenginewatch.com/
Matt Cutts Blog http://www.mattcutts.com/blog/
WebmasterWorld http://www.webmasterworld.com