It's quite difficult and it takes a lot of time/resources/man power. The easy way, to make it look like you have a search engine, is to create a simple site that basically, queries behind google and displays the same results, maybe in a different style. But to make your own search engine, and make it successful, it's almost impossible without let's say a few million dollars investment.
First, you need a good crawler, a script that parses the internet for all the sites and pages it can find, then you see which page links to which, get their content, analyze the content and try to figure out the main keywords of that page, then compare it to the links that page has and give it a score based on these factors, but that's just the main idea. Google engineers say there are more than 200 or 300 factors that affect a site's ranking... So think about it, 300 things you need to consider to decide a page's ranking :)